OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_CONTEXT_H_ | 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_CONTEXT_H_ |
6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_CONTEXT_H_ | 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_CONTEXT_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "chrome/browser/in_process_webkit/dom_storage_context.h" | 15 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
16 #include "chrome/browser/in_process_webkit/indexed_db_context.h" | 16 #include "chrome/browser/in_process_webkit/indexed_db_context.h" |
17 | 17 |
18 class Profile; | 18 class Profile; |
19 | 19 |
20 // There's one WebKitContext per profile. Various DispatcherHost classes | 20 // There's one WebKitContext per profile. Various DispatcherHost classes |
21 // have a pointer to the Context to store shared state. Unfortunately, this | 21 // have a pointer to the Context to store shared state. Unfortunately, this |
22 // class has become a bit of a dumping ground for calls made on the UI thread | 22 // class has become a bit of a dumping ground for calls made on the UI thread |
23 // that need to be proxied over to the WebKit thread. | 23 // that need to be proxied over to the WebKit thread. |
24 // | 24 // |
25 // This class is created on the UI thread and accessed on the UI, IO, and WebKit | 25 // This class is created on the UI thread and accessed on the UI, IO, and WebKit |
26 // threads. | 26 // threads. |
27 class WebKitContext : public base::RefCountedThreadSafe<WebKitContext> { | 27 class WebKitContext |
| 28 : public base::RefCountedThreadSafe<WebKitContext> { |
28 public: | 29 public: |
29 explicit WebKitContext(Profile* profile); | 30 explicit WebKitContext(Profile* profile, bool clear_local_state_on_exit); |
30 | 31 |
31 const FilePath& data_path() const { return data_path_; } | 32 const FilePath& data_path() const { return data_path_; } |
32 bool is_incognito() const { return is_incognito_; } | 33 bool is_incognito() const { return is_incognito_; } |
33 | 34 |
34 DOMStorageContext* dom_storage_context() { | 35 DOMStorageContext* dom_storage_context() { |
35 return dom_storage_context_.get(); | 36 return dom_storage_context_.get(); |
36 } | 37 } |
37 | 38 |
38 IndexedDBContext* indexed_db_context() { | 39 IndexedDBContext* indexed_db_context() { |
39 return indexed_db_context_.get(); | 40 return indexed_db_context_.get(); |
40 } | 41 } |
41 | 42 |
| 43 void set_clear_local_state_on_exit(bool clear_local_state) { |
| 44 clear_local_state_on_exit_ = clear_local_state; |
| 45 } |
| 46 |
42 #ifdef UNIT_TEST | 47 #ifdef UNIT_TEST |
43 // For unit tests, allow specifying a DOMStorageContext directly so it can be | 48 // For unit tests, allow specifying a DOMStorageContext directly so it can be |
44 // mocked. | 49 // mocked. |
45 void set_dom_storage_context(DOMStorageContext* dom_storage_context) { | 50 void set_dom_storage_context(DOMStorageContext* dom_storage_context) { |
46 dom_storage_context_.reset(dom_storage_context); | 51 dom_storage_context_.reset(dom_storage_context); |
47 } | 52 } |
48 #endif | 53 #endif |
49 | 54 |
50 // Tells the DOMStorageContext to purge any memory it does not need. | 55 // Tells the DOMStorageContext to purge any memory it does not need. |
51 void PurgeMemory(); | 56 void PurgeMemory(); |
52 | 57 |
53 // Tell all children (where applicable) to delete any objects that were | 58 // Tell all children (where applicable) to delete any objects that were |
54 // last modified on or after the following time. | 59 // last modified on or after the following time. |
55 void DeleteDataModifiedSince(const base::Time& cutoff, | 60 void DeleteDataModifiedSince(const base::Time& cutoff, |
56 const char* url_scheme_to_be_skipped, | 61 const char* url_scheme_to_be_skipped, |
57 const std::vector<string16>& protected_origins); | 62 const std::vector<string16>& protected_origins); |
58 | 63 |
59 // Delete the session storage namespace associated with this id. Can be | 64 // Delete the session storage namespace associated with this id. Can be |
60 // called from any thread. | 65 // called from any thread. |
61 void DeleteSessionStorageNamespace(int64 session_storage_namespace_id); | 66 void DeleteSessionStorageNamespace(int64 session_storage_namespace_id); |
62 | 67 |
63 private: | 68 private: |
64 friend class base::RefCountedThreadSafe<WebKitContext>; | 69 friend class base::RefCountedThreadSafe<WebKitContext>; |
65 ~WebKitContext(); | 70 virtual ~WebKitContext(); |
66 | 71 |
67 // Copies of profile data that can be accessed on any thread. | 72 // Copies of profile data that can be accessed on any thread. |
68 const FilePath data_path_; | 73 const FilePath data_path_; |
69 const bool is_incognito_; | 74 const bool is_incognito_; |
70 | 75 |
| 76 // True if the destructors of context objects should delete their files. |
| 77 bool clear_local_state_on_exit_; |
| 78 |
71 scoped_ptr<DOMStorageContext> dom_storage_context_; | 79 scoped_ptr<DOMStorageContext> dom_storage_context_; |
72 | 80 |
73 scoped_ptr<IndexedDBContext> indexed_db_context_; | 81 scoped_ptr<IndexedDBContext> indexed_db_context_; |
74 | 82 |
75 DISALLOW_IMPLICIT_CONSTRUCTORS(WebKitContext); | 83 DISALLOW_IMPLICIT_CONSTRUCTORS(WebKitContext); |
76 }; | 84 }; |
77 | 85 |
78 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_CONTEXT_H_ | 86 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_WEBKIT_CONTEXT_H_ |
OLD | NEW |