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

Side by Side Diff: chrome/browser/extensions/extension_prefs.cc

Issue 1695018: Adding ExtensionPrefs methods for storing update-when-idle data.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 months 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) 2009 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "chrome/browser/extensions/extension_prefs.h" 6 #include "chrome/browser/extensions/extension_prefs.h"
7 #include "chrome/common/extensions/extension.h" 7 #include "chrome/common/extensions/extension.h"
8 #include "chrome/common/pref_names.h" 8 #include "chrome/common/pref_names.h"
9 9
10 using base::Time; 10 using base::Time;
11 11
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 const wchar_t kExtensionToolbar[] = L"extensions.toolbar"; 47 const wchar_t kExtensionToolbar[] = L"extensions.toolbar";
48 48
49 // The key for a serialized Time value indicating the start of the day (from the 49 // The key for a serialized Time value indicating the start of the day (from the
50 // server's perspective) an extension last included a "ping" parameter during 50 // server's perspective) an extension last included a "ping" parameter during
51 // its update check. 51 // its update check.
52 const wchar_t kLastPingDay[] = L"lastpingday"; 52 const wchar_t kLastPingDay[] = L"lastpingday";
53 53
54 // Path for settings specific to blacklist update. 54 // Path for settings specific to blacklist update.
55 const wchar_t kExtensionsBlacklistUpdate[] = L"extensions.blacklistupdate"; 55 const wchar_t kExtensionsBlacklistUpdate[] = L"extensions.blacklistupdate";
56 56
57 // Path and sub-keys for the idle install info dictionary preference.
58 const wchar_t kIdleInstallInfo[] = L"idle_install_info";
59 const wchar_t kIdleInstallInfoCrxPath[] = L"crx_path";
60 const wchar_t kIdleInstallInfoVersion[] = L"version";
61 const wchar_t kIdleInstallInfoFetchTime[] = L"fetch_time";
62
63
57 // A preference that, if true, will allow this extension to run in incognito 64 // A preference that, if true, will allow this extension to run in incognito
58 // mode. 65 // mode.
59 const wchar_t kPrefIncognitoEnabled[] = L"incognito"; 66 const wchar_t kPrefIncognitoEnabled[] = L"incognito";
60 } 67 }
61 68
62 //////////////////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////////////////
63 70
64 namespace { 71 namespace {
65 72
66 // TODO(asargent) - This is cleanup code for a key that was introduced into 73 // TODO(asargent) - This is cleanup code for a key that was introduced into
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 extension_iter != extension_data->end_keys(); ++extension_iter) { 662 extension_iter != extension_data->end_keys(); ++extension_iter) {
656 if (WideToASCII(*extension_iter) == extension_id) { 663 if (WideToASCII(*extension_iter) == extension_id) {
657 return GetInstalledExtensionInfoImpl(extension_data.get(), 664 return GetInstalledExtensionInfoImpl(extension_data.get(),
658 extension_iter); 665 extension_iter);
659 } 666 }
660 } 667 }
661 668
662 return NULL; 669 return NULL;
663 } 670 }
664 671
672 void ExtensionPrefs::SetIdleInstallInfo(const std::string& extension_id,
673 const FilePath& crx_path,
674 const std::string& version,
675 const base::Time& fetch_time) {
676 DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
677 if (!extension_prefs) {
678 NOTREACHED();
679 return;
680 }
681 extension_prefs->Remove(kIdleInstallInfo, NULL);
682 DictionaryValue* info = new DictionaryValue();
683 info->SetString(kIdleInstallInfoCrxPath, crx_path.value());
684 info->SetString(kIdleInstallInfoVersion, version);
685 info->SetString(kIdleInstallInfoFetchTime,
686 Int64ToString(fetch_time.ToInternalValue()));
687 extension_prefs->Set(kIdleInstallInfo, info);
688 prefs_->ScheduleSavePersistentPrefs();
689 }
690
691 bool ExtensionPrefs::RemoveIdleInstallInfo(const std::string& extension_id) {
692 DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
693 if (!extension_prefs)
694 return false;
695 bool result = extension_prefs->Remove(kIdleInstallInfo, NULL);
696 prefs_->ScheduleSavePersistentPrefs();
697 return result;
698 }
699
700 bool ExtensionPrefs::GetIdleInstallInfo(const std::string& extension_id,
701 FilePath* crx_path,
702 std::string* version,
703 base::Time* fetch_time) {
704 DictionaryValue* extension_prefs = GetExtensionPref(extension_id);
705 if (!extension_prefs)
706 return false;
707
708 // Do all the reads from the prefs together, and don't do any assignment
709 // to the out parameters unless all the reads succeed.
710 DictionaryValue* info = NULL;
711 if (!extension_prefs->GetDictionary(kIdleInstallInfo, &info))
712 return false;
713
714 FilePath::StringType path_string;
715 if (!info->GetString(kIdleInstallInfoCrxPath, &path_string))
716 return false;
717
718 std::string tmp_version;
719 if (!info->GetString(kIdleInstallInfoVersion, &tmp_version))
720 return false;
721
722 std::string fetch_time_string;
723 if (!info->GetString(kIdleInstallInfoFetchTime, &fetch_time_string))
724 return false;
725
726 int64 fetch_time_value;
727 if (!StringToInt64(fetch_time_string, &fetch_time_value))
728 return false;
729
730 if (crx_path)
731 *crx_path = FilePath(path_string);
732
733 if (version)
734 *version = tmp_version;
735
736 if (fetch_time)
737 *fetch_time = base::Time::FromInternalValue(fetch_time_value);
738
739 return true;
740 }
741
742 std::set<std::string> ExtensionPrefs::GetIdleInstallInfoIds() {
743 std::set<std::string> result;
744
745 const DictionaryValue* extensions = prefs_->GetDictionary(kExtensionsPref);
746 if (!extensions)
747 return result;
748
749 for (DictionaryValue::key_iterator iter = extensions->begin_keys();
750 iter != extensions->end_keys(); ++iter) {
751 std::string id = WideToASCII(*iter);
752 if (!Extension::IdIsValid(id)) {
753 NOTREACHED();
754 continue;
755 }
756
757 DictionaryValue* extension_prefs = GetExtensionPref(id);
758 if (!extension_prefs)
759 continue;
760
761 DictionaryValue* info = NULL;
762 if (extension_prefs->GetDictionary(kIdleInstallInfo, &info))
763 result.insert(id);
764 }
765 return result;
766 }
767
768
665 // static 769 // static
666 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { 770 void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) {
667 prefs->RegisterDictionaryPref(kExtensionsPref); 771 prefs->RegisterDictionaryPref(kExtensionsPref);
668 prefs->RegisterListPref(kExtensionShelf); 772 prefs->RegisterListPref(kExtensionShelf);
669 prefs->RegisterListPref(kExtensionToolbar); 773 prefs->RegisterListPref(kExtensionToolbar);
670 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1); 774 prefs->RegisterIntegerPref(prefs::kExtensionToolbarSize, -1);
671 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); 775 prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate);
672 } 776 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/extension_prefs_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698