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 #include "chrome/browser/in_process_webkit/webkit_context.h" | 5 #include "chrome/browser/in_process_webkit/webkit_context.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/browser_thread.h" | 8 #include "chrome/browser/browser_thread.h" |
9 #include "chrome/browser/profile.h" | 9 #include "chrome/browser/profile.h" |
10 #include "chrome/browser/prefs/pref_service.h" | |
10 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
12 #include "chrome/common/notification_details.h" | |
13 #include "chrome/common/notification_type.h" | |
14 #include "chrome/common/pref_names.h" | |
15 #include "chrome/common/url_constants.h" | |
11 | 16 |
12 WebKitContext::WebKitContext(Profile* profile) | 17 WebKitContext::WebKitContext(Profile* profile) |
13 : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), | 18 : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), |
14 is_incognito_(profile->IsOffTheRecord()), | 19 is_incognito_(profile->IsOffTheRecord()), |
20 profile_(profile), | |
15 ALLOW_THIS_IN_INITIALIZER_LIST( | 21 ALLOW_THIS_IN_INITIALIZER_LIST( |
16 dom_storage_context_(new DOMStorageContext(this))), | 22 dom_storage_context_(new DOMStorageContext(this))), |
17 ALLOW_THIS_IN_INITIALIZER_LIST( | 23 ALLOW_THIS_IN_INITIALIZER_LIST( |
18 indexed_db_context_(new IndexedDBContext(this))) { | 24 indexed_db_context_(new IndexedDBContext(this))) { |
25 PrefService* prefs = profile->GetPrefs(); | |
26 clear_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
27 pref_change_registrar_.Init(prefs); | |
28 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | |
19 } | 29 } |
20 | 30 |
21 WebKitContext::~WebKitContext() { | 31 WebKitContext::~WebKitContext() { |
22 // If the WebKit thread was ever spun up, delete the object there. The task | 32 // If the WebKit thread was ever spun up, delete the object there. The task |
23 // will just get deleted if the WebKit thread isn't created (which only | 33 // will just get deleted if the WebKit thread isn't created (which only |
24 // happens during testing). | 34 // happens during testing). |
25 DOMStorageContext* dom_storage_context = dom_storage_context_.release(); | 35 DOMStorageContext* dom_storage_context = dom_storage_context_.release(); |
26 if (!BrowserThread::DeleteSoon( | 36 if (!BrowserThread::DeleteSoon( |
27 BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) { | 37 BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) { |
28 // The WebKit thread wasn't created, and the task got deleted without | 38 // The WebKit thread wasn't created, and the task got deleted without |
29 // freeing the DOMStorageContext, so delete it manually. | 39 // freeing the DOMStorageContext, so delete it manually. |
30 delete dom_storage_context; | 40 delete dom_storage_context; |
31 } | 41 } |
32 | 42 |
43 if (clear_on_exit()) { | |
jochen (gone - plz use gerrit)
2010/11/27 19:02:27
since we're explicitly deleting the context, you c
pastarmovj
2010/11/27 20:45:15
Done.
As a result I had to push(done upon constr
| |
44 const char* url_scheme_skipped = chrome::kExtensionScheme; | |
45 BrowserThread::PostTask( | |
46 BrowserThread::WEBKIT, FROM_HERE, | |
47 NewRunnableFunction(&IndexedDBContext::ClearLocalState, | |
48 data_path_, url_scheme_skipped)); | |
49 } | |
33 IndexedDBContext* indexed_db_context = indexed_db_context_.release(); | 50 IndexedDBContext* indexed_db_context = indexed_db_context_.release(); |
34 if (!BrowserThread::DeleteSoon( | 51 if (!BrowserThread::DeleteSoon( |
35 BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) { | 52 BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) { |
36 delete indexed_db_context; | 53 delete indexed_db_context; |
37 } | 54 } |
38 } | 55 } |
39 | 56 |
57 bool WebKitContext::clear_on_exit() const { | |
58 AutoLock auto_lock(lock_); | |
59 return clear_on_exit_; | |
pastarmovj
2010/11/27 20:45:15
Not needed anymore.
| |
60 } | |
61 | |
40 void WebKitContext::PurgeMemory() { | 62 void WebKitContext::PurgeMemory() { |
41 if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) { | 63 if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) { |
42 BrowserThread::PostTask( | 64 BrowserThread::PostTask( |
43 BrowserThread::WEBKIT, FROM_HERE, | 65 BrowserThread::WEBKIT, FROM_HERE, |
44 NewRunnableMethod(this, &WebKitContext::PurgeMemory)); | 66 NewRunnableMethod(this, &WebKitContext::PurgeMemory)); |
45 return; | 67 return; |
46 } | 68 } |
47 | 69 |
48 dom_storage_context_->PurgeMemory(); | 70 dom_storage_context_->PurgeMemory(); |
49 } | 71 } |
(...skipping 21 matching lines...) Expand all Loading... | |
71 BrowserThread::PostTask( | 93 BrowserThread::PostTask( |
72 BrowserThread::WEBKIT, FROM_HERE, | 94 BrowserThread::WEBKIT, FROM_HERE, |
73 NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace, | 95 NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace, |
74 session_storage_namespace_id)); | 96 session_storage_namespace_id)); |
75 return; | 97 return; |
76 } | 98 } |
77 | 99 |
78 dom_storage_context_->DeleteSessionStorageNamespace( | 100 dom_storage_context_->DeleteSessionStorageNamespace( |
79 session_storage_namespace_id); | 101 session_storage_namespace_id); |
80 } | 102 } |
103 | |
104 void WebKitContext::Observe(NotificationType type, | |
105 const NotificationSource& source, | |
106 const NotificationDetails& details) { | |
107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
jochen (gone - plz use gerrit)
2010/11/27 19:02:27
that shouldn't be required
pastarmovj
2010/11/27 20:45:15
Removed it.
| |
108 | |
109 if (NotificationType::PREF_CHANGED == type) { | |
110 std::string* name = Details<std::string>(details).ptr(); | |
111 if (prefs::kClearSiteDataOnExit == *name) { | |
112 AutoLock auto_lock(lock_); | |
113 clear_on_exit_ = profile_->GetPrefs()->GetBoolean( | |
114 prefs::kClearSiteDataOnExit); | |
115 LOG(WARNING) << "Option changed " << clear_on_exit_; | |
jochen (gone - plz use gerrit)
2010/11/27 19:02:27
please remove
pastarmovj
2010/11/27 20:45:15
Done. It was debug output to test if it is getting
| |
116 } | |
117 } | |
118 } | |
OLD | NEW |