Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef IOS_WEB_VIEW_INTERNAL_APP_APPLICATION_CONTEXT_H_ | |
| 6 #define IOS_WEB_VIEW_INTERNAL_APP_APPLICATION_CONTEXT_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 | |
| 15 namespace base { | |
| 16 template <typename T> | |
| 17 struct DefaultSingletonTraits; | |
| 18 class FilePath; | |
| 19 class SequencedTaskRunner; | |
| 20 } | |
| 21 | |
| 22 namespace net { | |
| 23 class URLRequestContextGetter; | |
| 24 } | |
| 25 | |
| 26 namespace net_log { | |
| 27 class ChromeNetLog; | |
| 28 } | |
| 29 | |
| 30 class PrefService; | |
| 31 | |
| 32 namespace ios_web_view { | |
| 33 | |
| 34 class WebViewIOThread; | |
| 35 | |
| 36 // Exposes application global state objects. | |
| 37 class ApplicationContext { | |
| 38 public: | |
| 39 static ApplicationContext* GetInstance(); | |
| 40 | |
| 41 // Gets the preferences associated with this application. | |
| 42 PrefService* GetLocalState(); | |
| 43 | |
| 44 // Gets the URL request context associated with this application. | |
| 45 net::URLRequestContextGetter* GetSystemURLRequestContext(); | |
| 46 | |
| 47 // Gets the locale used by the application. | |
| 48 const std::string& GetApplicationLocale(); | |
| 49 | |
| 50 // Creates state tied to application threads. It is expected this will be | |
| 51 // called from web::WebMainParts::PreCreateThreads. | |
| 52 void PreCreateThreads(); | |
| 53 | |
| 54 // Saves applicaiton context state if |local_state_| exists. This should be | |
|
sdefresne
2017/06/02 09:03:51
applicaiton → application
michaeldo
2017/06/02 15:46:57
Done.
| |
| 55 // called during shutdown to save application state. | |
| 56 void SaveState(); | |
| 57 | |
| 58 // Destroys state tied to application threads. It is expected this will be | |
| 59 // called from web::WebMainParts::PostDestroyThreads. | |
| 60 void PostDestroyThreads(); | |
| 61 | |
| 62 private: | |
| 63 ApplicationContext(); | |
|
sdefresne
2017/06/02 09:03:51
nit: move this below "friend struct base::DefaultS
michaeldo
2017/06/02 15:46:57
Done. Thank you for reference.
| |
| 64 ~ApplicationContext(); | |
| 65 friend struct base::DefaultSingletonTraits<ApplicationContext>; | |
| 66 | |
| 67 // Gets the ChromeNetLog. | |
| 68 net_log::ChromeNetLog* GetNetLog(); | |
| 69 | |
| 70 // Gets the WebViewIOThread. | |
| 71 WebViewIOThread* GetWebViewIOThread(); | |
| 72 | |
| 73 // Returns the path to the application level preferences. | |
| 74 static base::FilePath GetLocalStatePath(); | |
| 75 | |
| 76 // Sets the locale used by the application. | |
| 77 void SetApplicationLocale(const std::string& locale); | |
| 78 | |
| 79 THREAD_CHECKER(thread_checker_); | |
|
sdefresne
2017/06/02 09:03:51
optional: I think you can use a SEQUENCE_CHECKER h
michaeldo
2017/06/02 15:46:57
Done.
| |
| 80 std::unique_ptr<PrefService> local_state_; | |
| 81 std::unique_ptr<net_log::ChromeNetLog> net_log_; | |
| 82 std::unique_ptr<WebViewIOThread> web_view_io_thread_; | |
| 83 std::string application_locale_; | |
| 84 | |
| 85 // Sequenced task runner for local state related I/O tasks. | |
| 86 const scoped_refptr<base::SequencedTaskRunner> local_state_task_runner_; | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(ApplicationContext); | |
| 89 }; | |
| 90 | |
| 91 } // namespace ios_web_view | |
| 92 | |
| 93 #endif // IOS_WEB_VIEW_INTERNAL_APP_APPLICATION_CONTEXT_H_ | |
| OLD | NEW |