Chromium Code Reviews| 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" | |
| 11 | 15 |
| 12 WebKitContext::WebKitContext(Profile* profile) | 16 WebKitContext::WebKitContext(Profile* profile) |
| 13 : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), | 17 : data_path_(profile->IsOffTheRecord() ? FilePath() : profile->GetPath()), |
| 14 is_incognito_(profile->IsOffTheRecord()), | 18 is_incognito_(profile->IsOffTheRecord()), |
| 19 profile_(profile), | |
| 15 ALLOW_THIS_IN_INITIALIZER_LIST( | 20 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 16 dom_storage_context_(new DOMStorageContext(this))), | 21 dom_storage_context_(new DOMStorageContext(this))), |
| 17 ALLOW_THIS_IN_INITIALIZER_LIST( | 22 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 18 indexed_db_context_(new IndexedDBContext(this))) { | 23 indexed_db_context_(new IndexedDBContext(this))) { |
| 24 PrefService* prefs = profile->GetPrefs(); | |
| 25 clear_local_state_on_exit_ = prefs->GetBoolean(prefs::kClearSiteDataOnExit); | |
| 26 pref_change_registrar_.Init(prefs); | |
| 27 pref_change_registrar_.Add(prefs::kClearSiteDataOnExit, this); | |
| 19 } | 28 } |
| 20 | 29 |
| 21 WebKitContext::~WebKitContext() { | 30 WebKitContext::~WebKitContext() { |
| 22 // If the WebKit thread was ever spun up, delete the object there. The task | 31 // 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 | 32 // will just get deleted if the WebKit thread isn't created (which only |
| 24 // happens during testing). | 33 // happens during testing). |
| 25 DOMStorageContext* dom_storage_context = dom_storage_context_.release(); | 34 DOMStorageContext* dom_storage_context = dom_storage_context_.release(); |
| 26 if (!BrowserThread::DeleteSoon( | 35 if (!BrowserThread::DeleteSoon( |
| 27 BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) { | 36 BrowserThread::WEBKIT, FROM_HERE, dom_storage_context)) { |
| 28 // The WebKit thread wasn't created, and the task got deleted without | 37 // The WebKit thread wasn't created, and the task got deleted without |
| 29 // freeing the DOMStorageContext, so delete it manually. | 38 // freeing the DOMStorageContext, so delete it manually. |
| 30 delete dom_storage_context; | 39 delete dom_storage_context; |
| 31 } | 40 } |
| 32 | 41 |
| 42 indexed_db_context_->SetClearLocalStateOnExit(clear_local_state_on_exit_); | |
| 33 IndexedDBContext* indexed_db_context = indexed_db_context_.release(); | 43 IndexedDBContext* indexed_db_context = indexed_db_context_.release(); |
| 34 if (!BrowserThread::DeleteSoon( | 44 if (!BrowserThread::DeleteSoon( |
| 35 BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) { | 45 BrowserThread::WEBKIT, FROM_HERE, indexed_db_context)) { |
| 36 delete indexed_db_context; | 46 delete indexed_db_context; |
| 37 } | 47 } |
| 38 } | 48 } |
| 39 | 49 |
| 40 void WebKitContext::PurgeMemory() { | 50 void WebKitContext::PurgeMemory() { |
| 41 if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) { | 51 if (!BrowserThread::CurrentlyOn(BrowserThread::WEBKIT)) { |
| 42 BrowserThread::PostTask( | 52 BrowserThread::PostTask( |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 71 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
| 72 BrowserThread::WEBKIT, FROM_HERE, | 82 BrowserThread::WEBKIT, FROM_HERE, |
| 73 NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace, | 83 NewRunnableMethod(this, &WebKitContext::DeleteSessionStorageNamespace, |
| 74 session_storage_namespace_id)); | 84 session_storage_namespace_id)); |
| 75 return; | 85 return; |
| 76 } | 86 } |
| 77 | 87 |
| 78 dom_storage_context_->DeleteSessionStorageNamespace( | 88 dom_storage_context_->DeleteSessionStorageNamespace( |
| 79 session_storage_namespace_id); | 89 session_storage_namespace_id); |
| 80 } | 90 } |
| 91 | |
| 92 void WebKitContext::Observe(NotificationType type, | |
| 93 const NotificationSource& source, | |
| 94 const NotificationDetails& details) { | |
| 95 if (NotificationType::PREF_CHANGED == type) { | |
| 96 std::string* name = Details<std::string>(details).ptr(); | |
| 97 if (prefs::kClearSiteDataOnExit == *name) | |
| 98 { | |
| 99 clear_local_state_on_exit_ = profile_->GetPrefs()->GetBoolean( | |
|
jochen (gone - plz use gerrit)
2010/11/29 10:45:24
the notification source is the pref service, so yo
pastarmovj
2010/11/29 12:50:37
Done.
| |
| 100 prefs::kClearSiteDataOnExit); | |
| 101 } | |
| 102 } | |
| 103 } | |
| OLD | NEW |