| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autocomplete/shortcuts_backend.h" | 5 #include "chrome/browser/autocomplete/shortcuts_backend.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 72 |
| 73 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) | 73 ShortcutsBackend::ShortcutsBackend(Profile* profile, bool suppress_db) |
| 74 : current_state_(NOT_INITIALIZED), | 74 : current_state_(NOT_INITIALIZED), |
| 75 no_db_access_(suppress_db) { | 75 no_db_access_(suppress_db) { |
| 76 if (!suppress_db) { | 76 if (!suppress_db) { |
| 77 db_ = new history::ShortcutsDatabase( | 77 db_ = new history::ShortcutsDatabase( |
| 78 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); | 78 profile->GetPath().Append(chrome::kShortcutsDatabaseName)); |
| 79 } | 79 } |
| 80 // |profile| can be NULL in tests. | 80 // |profile| can be NULL in tests. |
| 81 if (profile) { | 81 if (profile) { |
| 82 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 82 notification_registrar_.Add( |
| 83 content::Source<Profile>(profile)); | 83 this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| 84 notification_registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, | 84 content::Source<Profile>(profile)); |
| 85 content::Source<Profile>(profile)); | 85 notification_registrar_.Add( |
| 86 this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
| 87 content::Source<Profile>(profile)); |
| 86 } | 88 } |
| 87 } | 89 } |
| 88 | 90 |
| 89 bool ShortcutsBackend::Init() { | 91 bool ShortcutsBackend::Init() { |
| 90 if (current_state_ != NOT_INITIALIZED) | 92 if (current_state_ != NOT_INITIALIZED) |
| 91 return false; | 93 return false; |
| 92 | 94 |
| 93 if (no_db_access_) { | 95 if (no_db_access_) { |
| 94 current_state_ = INITIALIZED; | 96 current_state_ = INITIALIZED; |
| 95 return true; | 97 return true; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 BrowserThread::CurrentlyOn(BrowserThread::UI)); | 151 BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 150 notification_registrar_.RemoveAll(); | 152 notification_registrar_.RemoveAll(); |
| 151 } | 153 } |
| 152 | 154 |
| 153 void ShortcutsBackend::Observe(int type, | 155 void ShortcutsBackend::Observe(int type, |
| 154 const content::NotificationSource& source, | 156 const content::NotificationSource& source, |
| 155 const content::NotificationDetails& details) { | 157 const content::NotificationDetails& details) { |
| 156 if (!initialized()) | 158 if (!initialized()) |
| 157 return; | 159 return; |
| 158 | 160 |
| 159 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) { | 161 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED) { |
| 160 // When an extension is unloaded, we want to remove any Shortcuts associated | 162 // When an extension is unloaded, we want to remove any Shortcuts associated |
| 161 // with it. | 163 // with it. |
| 162 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>( | 164 DeleteShortcutsWithURL(content::Details<extensions::UnloadedExtensionInfo>( |
| 163 details)->extension->url(), false); | 165 details)->extension->url(), false); |
| 164 return; | 166 return; |
| 165 } | 167 } |
| 166 | 168 |
| 167 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); | 169 DCHECK_EQ(chrome::NOTIFICATION_HISTORY_URLS_DELETED, type); |
| 168 const history::URLsDeletedDetails* deleted_details = | 170 const history::URLsDeletedDetails* deleted_details = |
| 169 content::Details<const history::URLsDeletedDetails>(details).ptr(); | 171 content::Details<const history::URLsDeletedDetails>(details).ptr(); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 guid_map_.clear(); | 300 guid_map_.clear(); |
| 299 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, | 301 FOR_EACH_OBSERVER(ShortcutsBackendObserver, observer_list_, |
| 300 OnShortcutsChanged()); | 302 OnShortcutsChanged()); |
| 301 return no_db_access_ || | 303 return no_db_access_ || |
| 302 BrowserThread::PostTask( | 304 BrowserThread::PostTask( |
| 303 BrowserThread::DB, FROM_HERE, | 305 BrowserThread::DB, FROM_HERE, |
| 304 base::Bind(base::IgnoreResult( | 306 base::Bind(base::IgnoreResult( |
| 305 &history::ShortcutsDatabase::DeleteAllShortcuts), | 307 &history::ShortcutsDatabase::DeleteAllShortcuts), |
| 306 db_.get())); | 308 db_.get())); |
| 307 } | 309 } |
| OLD | NEW |