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/background_page_tracker.h" | 5 #include "chrome/browser/background_page_tracker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 183 |
184 // We will make two passes to update the list: | 184 // We will make two passes to update the list: |
185 // 1) Walk our list, and make sure that there's a corresponding extension for | 185 // 1) Walk our list, and make sure that there's a corresponding extension for |
186 // each item in the list. If not, delete it (extension was uninstalled). | 186 // each item in the list. If not, delete it (extension was uninstalled). |
187 // 2) Walk the set of currently loaded extensions and background contents, and | 187 // 2) Walk the set of currently loaded extensions and background contents, and |
188 // make sure there's an entry in our list for each one. If not, create one. | 188 // make sure there's an entry in our list for each one. If not, create one. |
189 | 189 |
190 PrefService* prefs = GetPrefService(); | 190 PrefService* prefs = GetPrefService(); |
191 std::set<std::string> keys_to_delete; | 191 std::set<std::string> keys_to_delete; |
192 bool pref_modified = false; | 192 bool pref_modified = false; |
| 193 // If we've never set any prefs, then this is the first launch ever, so we |
| 194 // want to automatically mark all existing extensions as acknowledged. |
| 195 bool first_launch = |
| 196 prefs->GetDictionary(prefs::kKnownBackgroundPages) == NULL; |
193 DictionaryValue* contents = | 197 DictionaryValue* contents = |
194 prefs->GetMutableDictionary(prefs::kKnownBackgroundPages); | 198 prefs->GetMutableDictionary(prefs::kKnownBackgroundPages); |
195 for (DictionaryValue::key_iterator it = contents->begin_keys(); | 199 for (DictionaryValue::key_iterator it = contents->begin_keys(); |
196 it != contents->end_keys(); ++it) { | 200 it != contents->end_keys(); ++it) { |
197 // Check to make sure that the parent extension is still enabled. | 201 // Check to make sure that the parent extension is still enabled. |
198 const Extension* extension = extensions_service->GetExtensionById( | 202 const Extension* extension = extensions_service->GetExtensionById( |
199 *it, false); | 203 *it, false); |
200 // If the extension is not loaded, add the id to our list of keys to delete | 204 // If the extension is not loaded, add the id to our list of keys to delete |
201 // later (can't delete now since we're still iterating). | 205 // later (can't delete now since we're still iterating). |
202 if (!extension) { | 206 if (!extension) { |
(...skipping 11 matching lines...) Expand all Loading... |
214 // Look for new extensions/background contents. | 218 // Look for new extensions/background contents. |
215 const ExtensionList* list = extensions_service->extensions(); | 219 const ExtensionList* list = extensions_service->extensions(); |
216 for (ExtensionList::const_iterator iter = list->begin(); | 220 for (ExtensionList::const_iterator iter = list->begin(); |
217 iter != list->begin(); | 221 iter != list->begin(); |
218 ++iter) { | 222 ++iter) { |
219 // Any extension with a background page should be in our list. | 223 // Any extension with a background page should be in our list. |
220 if ((*iter)->background_url().is_valid()) { | 224 if ((*iter)->background_url().is_valid()) { |
221 // If we have not seen this extension ID before, add it to our list. | 225 // If we have not seen this extension ID before, add it to our list. |
222 if (!contents->HasKey((*iter)->id())) { | 226 if (!contents->HasKey((*iter)->id())) { |
223 contents->SetWithoutPathExpansion( | 227 contents->SetWithoutPathExpansion( |
224 (*iter)->id(), Value::CreateBooleanValue(false)); | 228 (*iter)->id(), Value::CreateBooleanValue(first_launch)); |
225 pref_modified = true; | 229 pref_modified = true; |
226 } | 230 } |
227 } | 231 } |
228 } | 232 } |
229 | 233 |
230 // Add all apps with background contents also. | 234 // Add all apps with background contents also. |
231 BackgroundContentsService* background_contents_service = | 235 BackgroundContentsService* background_contents_service = |
232 profile->GetBackgroundContentsService(); | 236 profile->GetBackgroundContentsService(); |
233 std::vector<BackgroundContents*> background_contents = | 237 std::vector<BackgroundContents*> background_contents = |
234 background_contents_service->GetBackgroundContents(); | 238 background_contents_service->GetBackgroundContents(); |
235 for (std::vector<BackgroundContents*>::const_iterator iter = | 239 for (std::vector<BackgroundContents*>::const_iterator iter = |
236 background_contents.begin(); | 240 background_contents.begin(); |
237 iter != background_contents.end(); | 241 iter != background_contents.end(); |
238 ++iter) { | 242 ++iter) { |
239 std::string application_id = UTF16ToUTF8( | 243 std::string application_id = UTF16ToUTF8( |
240 background_contents_service->GetParentApplicationId(*iter)); | 244 background_contents_service->GetParentApplicationId(*iter)); |
241 if (!contents->HasKey(application_id)) { | 245 if (!contents->HasKey(application_id)) { |
242 contents->SetWithoutPathExpansion( | 246 contents->SetWithoutPathExpansion( |
243 application_id, Value::CreateBooleanValue(false)); | 247 application_id, Value::CreateBooleanValue(first_launch)); |
244 pref_modified = true; | 248 pref_modified = true; |
245 } | 249 } |
246 } | 250 } |
247 | 251 |
248 // Register for when new pages are loaded/unloaded so we can update our list. | 252 // Register for when new pages are loaded/unloaded so we can update our list. |
249 registrar_.Add(this, NotificationType::EXTENSION_LOADED, | 253 registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
250 NotificationService::AllSources()); | 254 NotificationService::AllSources()); |
251 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 255 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
252 NotificationService::AllSources()); | 256 NotificationService::AllSources()); |
253 registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_OPENED, | 257 registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_OPENED, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 prefs->ScheduleSavePersistentPrefs(); | 291 prefs->ScheduleSavePersistentPrefs(); |
288 SendChangeNotification(); | 292 SendChangeNotification(); |
289 } | 293 } |
290 | 294 |
291 void BackgroundPageTracker::SendChangeNotification() { | 295 void BackgroundPageTracker::SendChangeNotification() { |
292 NotificationService::current()->Notify( | 296 NotificationService::current()->Notify( |
293 NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED, | 297 NotificationType::BACKGROUND_PAGE_TRACKER_CHANGED, |
294 Source<BackgroundPageTracker>(this), | 298 Source<BackgroundPageTracker>(this), |
295 NotificationService::NoDetails()); | 299 NotificationService::NoDetails()); |
296 } | 300 } |
OLD | NEW |