Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: chrome/browser/background/background_contents_service.cc

Issue 106433007: Update some uses of Value in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/background/background_contents_service.h" 5 #include "chrome/browser/background/background_contents_service.h"
6 6
7 #include "apps/app_load_service.h" 7 #include "apps/app_load_service.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 491 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
492 base::Bind(&ReloadExtension, extension->id(), profile), 492 base::Bind(&ReloadExtension, extension->id(), profile),
493 base::TimeDelta::FromMilliseconds(restart_delay_in_ms_)); 493 base::TimeDelta::FromMilliseconds(restart_delay_in_ms_));
494 } 494 }
495 495
496 // Loads all background contents whose urls have been stored in prefs. 496 // Loads all background contents whose urls have been stored in prefs.
497 void BackgroundContentsService::LoadBackgroundContentsFromPrefs( 497 void BackgroundContentsService::LoadBackgroundContentsFromPrefs(
498 Profile* profile) { 498 Profile* profile) {
499 if (!prefs_) 499 if (!prefs_)
500 return; 500 return;
501 const DictionaryValue* contents = 501 const base::DictionaryValue* contents =
502 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); 502 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents);
503 if (!contents) 503 if (!contents)
504 return; 504 return;
505 ExtensionService* extensions_service = 505 ExtensionService* extensions_service =
506 extensions::ExtensionSystem::Get(profile)->extension_service(); 506 extensions::ExtensionSystem::Get(profile)->extension_service();
507 DCHECK(extensions_service); 507 DCHECK(extensions_service);
508 for (DictionaryValue::Iterator it(*contents); !it.IsAtEnd(); it.Advance()) { 508 for (base::DictionaryValue::Iterator it(*contents);
509 !it.IsAtEnd(); it.Advance()) {
509 // Check to make sure that the parent extension is still enabled. 510 // Check to make sure that the parent extension is still enabled.
510 const Extension* extension = extensions_service-> 511 const Extension* extension = extensions_service->
511 GetExtensionById(it.key(), false); 512 GetExtensionById(it.key(), false);
512 if (!extension) { 513 if (!extension) {
513 // We should never reach here - it should not be possible for an app 514 // We should never reach here - it should not be possible for an app
514 // to become uninstalled without the associated BackgroundContents being 515 // to become uninstalled without the associated BackgroundContents being
515 // unregistered via the EXTENSIONS_UNLOADED notification, unless there's a 516 // unregistered via the EXTENSIONS_UNLOADED notification, unless there's a
516 // crash before we could save our prefs, or if the user deletes the 517 // crash before we could save our prefs, or if the user deletes the
517 // extension files manually rather than uninstalling it. 518 // extension files manually rather than uninstalling it.
518 NOTREACHED() << "No extension found for BackgroundContents - id = " 519 NOTREACHED() << "No extension found for BackgroundContents - id = "
(...skipping 25 matching lines...) Expand all
544 LoadBackgroundContents(profile, 545 LoadBackgroundContents(profile,
545 BackgroundInfo::GetBackgroundURL(extension), 546 BackgroundInfo::GetBackgroundURL(extension),
546 ASCIIToUTF16("background"), 547 ASCIIToUTF16("background"),
547 UTF8ToUTF16(extension->id())); 548 UTF8ToUTF16(extension->id()));
548 return; 549 return;
549 } 550 }
550 551
551 // Now look in the prefs. 552 // Now look in the prefs.
552 if (!prefs_) 553 if (!prefs_)
553 return; 554 return;
554 const DictionaryValue* contents = 555 const base::DictionaryValue* contents =
555 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); 556 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents);
556 if (!contents) 557 if (!contents)
557 return; 558 return;
558 LoadBackgroundContentsFromDictionary(profile, extension_id, contents); 559 LoadBackgroundContentsFromDictionary(profile, extension_id, contents);
559 } 560 }
560 561
561 void BackgroundContentsService::LoadBackgroundContentsFromDictionary( 562 void BackgroundContentsService::LoadBackgroundContentsFromDictionary(
562 Profile* profile, 563 Profile* profile,
563 const std::string& extension_id, 564 const std::string& extension_id,
564 const DictionaryValue* contents) { 565 const base::DictionaryValue* contents) {
565 ExtensionService* extensions_service = 566 ExtensionService* extensions_service =
566 extensions::ExtensionSystem::Get(profile)->extension_service(); 567 extensions::ExtensionSystem::Get(profile)->extension_service();
567 DCHECK(extensions_service); 568 DCHECK(extensions_service);
568 569
569 const DictionaryValue* dict; 570 const base::DictionaryValue* dict;
570 if (!contents->GetDictionaryWithoutPathExpansion(extension_id, &dict) || 571 if (!contents->GetDictionaryWithoutPathExpansion(extension_id, &dict) ||
571 dict == NULL) 572 dict == NULL)
572 return; 573 return;
573 574
574 base::string16 frame_name; 575 base::string16 frame_name;
575 std::string url; 576 std::string url;
576 dict->GetString(kUrlKey, &url); 577 dict->GetString(kUrlKey, &url);
577 dict->GetString(kFrameNameKey, &frame_name); 578 dict->GetString(kFrameNameKey, &frame_name);
578 LoadBackgroundContents(profile, 579 LoadBackgroundContents(profile,
579 GURL(url), 580 GURL(url),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 BackgroundContents* background_contents) { 659 BackgroundContents* background_contents) {
659 DCHECK(IsTracked(background_contents)); 660 DCHECK(IsTracked(background_contents));
660 if (!prefs_) 661 if (!prefs_)
661 return; 662 return;
662 663
663 // We store the first URL we receive for a given application. If there's 664 // We store the first URL we receive for a given application. If there's
664 // already an entry for this application, no need to do anything. 665 // already an entry for this application, no need to do anything.
665 // TODO(atwilson): Verify that this is the desired behavior based on developer 666 // TODO(atwilson): Verify that this is the desired behavior based on developer
666 // feedback (http://crbug.com/47118). 667 // feedback (http://crbug.com/47118).
667 DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents); 668 DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents);
668 DictionaryValue* pref = update.Get(); 669 base::DictionaryValue* pref = update.Get();
669 const base::string16& appid = GetParentApplicationId(background_contents); 670 const base::string16& appid = GetParentApplicationId(background_contents);
670 DictionaryValue* current; 671 base::DictionaryValue* current;
671 if (pref->GetDictionaryWithoutPathExpansion(UTF16ToUTF8(appid), &current)) 672 if (pref->GetDictionaryWithoutPathExpansion(UTF16ToUTF8(appid), &current))
672 return; 673 return;
673 674
674 // No entry for this application yet, so add one. 675 // No entry for this application yet, so add one.
675 DictionaryValue* dict = new DictionaryValue(); 676 base::DictionaryValue* dict = new base::DictionaryValue();
676 dict->SetString(kUrlKey, background_contents->GetURL().spec()); 677 dict->SetString(kUrlKey, background_contents->GetURL().spec());
677 dict->SetString(kFrameNameKey, contents_map_[appid].frame_name); 678 dict->SetString(kFrameNameKey, contents_map_[appid].frame_name);
678 pref->SetWithoutPathExpansion(UTF16ToUTF8(appid), dict); 679 pref->SetWithoutPathExpansion(UTF16ToUTF8(appid), dict);
679 } 680 }
680 681
681 bool BackgroundContentsService::HasRegisteredBackgroundContents( 682 bool BackgroundContentsService::HasRegisteredBackgroundContents(
682 const base::string16& app_id) { 683 const base::string16& app_id) {
683 if (!prefs_) 684 if (!prefs_)
684 return false; 685 return false;
685 std::string app = UTF16ToUTF8(app_id); 686 std::string app = UTF16ToUTF8(app_id);
686 const DictionaryValue* contents = 687 const base::DictionaryValue* contents =
687 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); 688 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents);
688 return contents->HasKey(app); 689 return contents->HasKey(app);
689 } 690 }
690 691
691 void BackgroundContentsService::UnregisterBackgroundContents( 692 void BackgroundContentsService::UnregisterBackgroundContents(
692 BackgroundContents* background_contents) { 693 BackgroundContents* background_contents) {
693 if (!prefs_) 694 if (!prefs_)
694 return; 695 return;
695 DCHECK(IsTracked(background_contents)); 696 DCHECK(IsTracked(background_contents));
696 const base::string16 appid = GetParentApplicationId(background_contents); 697 const base::string16 appid = GetParentApplicationId(background_contents);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 bool user_gesture, 758 bool user_gesture,
758 bool* was_blocked) { 759 bool* was_blocked) {
759 Browser* browser = chrome::FindLastActiveWithProfile( 760 Browser* browser = chrome::FindLastActiveWithProfile(
760 Profile::FromBrowserContext(new_contents->GetBrowserContext()), 761 Profile::FromBrowserContext(new_contents->GetBrowserContext()),
761 chrome::GetActiveDesktop()); 762 chrome::GetActiveDesktop());
762 if (browser) { 763 if (browser) {
763 chrome::AddWebContents(browser, NULL, new_contents, disposition, 764 chrome::AddWebContents(browser, NULL, new_contents, disposition,
764 initial_pos, user_gesture, was_blocked); 765 initial_pos, user_gesture, was_blocked);
765 } 766 }
766 } 767 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698