2012-04-03 03:34:16 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_CONTEXT_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_CONTEXT_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "include/cef_app.h"
|
|
|
|
|
2013-02-27 18:56:03 +01:00
|
|
|
#include "base/files/file_path.h"
|
2012-11-30 20:08:20 +01:00
|
|
|
#include "base/files/scoped_temp_dir.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
#include "base/memory/scoped_ptr.h"
|
|
|
|
#include "base/threading/platform_thread.h"
|
2013-09-03 18:43:31 +02:00
|
|
|
#include "content/public/browser/notification_observer.h"
|
|
|
|
#include "content/public/browser/notification_registrar.h"
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
namespace base {
|
|
|
|
class WaitableEvent;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace content {
|
|
|
|
class ContentMainRunner;
|
|
|
|
}
|
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
namespace printing {
|
|
|
|
class PrintJobManager;
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
class CefBrowserHostImpl;
|
|
|
|
class CefMainDelegate;
|
2012-10-18 00:45:49 +02:00
|
|
|
class CefTraceSubscriber;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-03 20:06:25 +02:00
|
|
|
class CefContext : public content::NotificationObserver {
|
2012-04-03 03:34:16 +02:00
|
|
|
public:
|
|
|
|
typedef std::list<CefRefPtr<CefBrowserHostImpl> > BrowserList;
|
|
|
|
|
|
|
|
CefContext();
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefContext() override;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-03 20:06:25 +02:00
|
|
|
// Returns the singleton CefContext instance.
|
|
|
|
static CefContext* Get();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// These methods will be called on the main application thread.
|
|
|
|
bool Initialize(const CefMainArgs& args,
|
|
|
|
const CefSettings& settings,
|
2013-11-15 19:47:02 +01:00
|
|
|
CefRefPtr<CefApp> application,
|
|
|
|
void* windows_sandbox_info);
|
2012-04-03 03:34:16 +02:00
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
// Returns true if the current thread is the initialization thread.
|
|
|
|
bool OnInitThread();
|
|
|
|
|
|
|
|
// Returns true if the context is initialized.
|
|
|
|
bool initialized() { return initialized_; }
|
|
|
|
|
|
|
|
// Returns true if the context is shutting down.
|
|
|
|
bool shutting_down() { return shutting_down_; }
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
// Retrieve the path at which cache data will be stored on disk.
|
2013-02-23 01:43:28 +01:00
|
|
|
const base::FilePath& cache_path() const { return cache_path_; }
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
const CefSettings& settings() const { return settings_; }
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2013-10-23 21:30:47 +02:00
|
|
|
printing::PrintJobManager* print_job_manager() const {
|
|
|
|
return print_job_manager_.get();
|
|
|
|
}
|
|
|
|
|
2012-10-18 00:45:49 +02:00
|
|
|
CefTraceSubscriber* GetTraceSubscriber();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
private:
|
2012-06-19 18:29:49 +02:00
|
|
|
void OnContextInitialized();
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Performs shutdown actions that need to occur on the UI thread before any
|
|
|
|
// threads are destroyed.
|
2012-04-11 20:00:55 +02:00
|
|
|
void FinishShutdownOnUIThread(base::WaitableEvent* uithread_shutdown_event);
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
// Destroys the main runner and related objects.
|
|
|
|
void FinalizeShutdown();
|
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
// NotificationObserver implementation.
|
2014-11-12 20:25:15 +01:00
|
|
|
void Observe(int type,
|
|
|
|
const content::NotificationSource& source,
|
|
|
|
const content::NotificationDetails& details) override;
|
2013-09-03 18:43:31 +02:00
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
// Track context state.
|
|
|
|
bool initialized_;
|
|
|
|
bool shutting_down_;
|
|
|
|
|
|
|
|
// The thread on which the context was initialized.
|
|
|
|
base::PlatformThreadId init_thread_id_;
|
|
|
|
|
|
|
|
CefSettings settings_;
|
2013-02-23 01:43:28 +01:00
|
|
|
base::FilePath cache_path_;
|
2012-11-30 20:08:20 +01:00
|
|
|
base::ScopedTempDir cache_temp_dir_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
scoped_ptr<CefMainDelegate> main_delegate_;
|
|
|
|
scoped_ptr<content::ContentMainRunner> main_runner_;
|
2012-10-18 00:45:49 +02:00
|
|
|
scoped_ptr<CefTraceSubscriber> trace_subscriber_;
|
2012-04-03 03:34:16 +02:00
|
|
|
|
2013-09-03 18:43:31 +02:00
|
|
|
// Only accessed on the UI Thread.
|
|
|
|
scoped_ptr<content::NotificationRegistrar> registrar_;
|
2013-10-23 21:30:47 +02:00
|
|
|
scoped_ptr<printing::PrintJobManager> print_job_manager_;
|
2012-04-03 03:34:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Helper macro that returns true if the global context is in a valid state.
|
|
|
|
#define CONTEXT_STATE_VALID() \
|
2013-09-03 20:06:25 +02:00
|
|
|
(CefContext::Get() && CefContext::Get()->initialized() && \
|
|
|
|
!CefContext::Get()->shutting_down())
|
2012-04-03 03:34:16 +02:00
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_CONTEXT_H_
|