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

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 14858037: Move [Get|Set]WebStoreLogin methods from ExtensionPrefs to WebstorePrivateAPI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for CQ Created 7 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/extensions/api/webstore_private/webstore_private_api.h" 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
6 6
7 #include "apps/app_launcher.h" 7 #include "apps/app_launcher.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 91
92 const char kAppInstallBubbleKey[] = "appInstallBubble"; 92 const char kAppInstallBubbleKey[] = "appInstallBubble";
93 const char kEnableLauncherKey[] = "enableLauncher"; 93 const char kEnableLauncherKey[] = "enableLauncher";
94 const char kIconDataKey[] = "iconData"; 94 const char kIconDataKey[] = "iconData";
95 const char kIconUrlKey[] = "iconUrl"; 95 const char kIconUrlKey[] = "iconUrl";
96 const char kIdKey[] = "id"; 96 const char kIdKey[] = "id";
97 const char kLocalizedNameKey[] = "localizedName"; 97 const char kLocalizedNameKey[] = "localizedName";
98 const char kLoginKey[] = "login"; 98 const char kLoginKey[] = "login";
99 const char kManifestKey[] = "manifest"; 99 const char kManifestKey[] = "manifest";
100 100
101 // A preference set by the web store to indicate login information for
102 // purchased apps.
103 const char kWebstoreLogin[] = "extensions.webstore_login";
104
101 const char kCannotSpecifyIconDataAndUrlError[] = 105 const char kCannotSpecifyIconDataAndUrlError[] =
102 "You cannot specify both icon data and an icon url"; 106 "You cannot specify both icon data and an icon url";
103 const char kInvalidIconUrlError[] = "Invalid icon url"; 107 const char kInvalidIconUrlError[] = "Invalid icon url";
104 const char kInvalidIdError[] = "Invalid id"; 108 const char kInvalidIdError[] = "Invalid id";
105 const char kInvalidManifestError[] = "Invalid manifest"; 109 const char kInvalidManifestError[] = "Invalid manifest";
106 const char kNoPreviousBeginInstallWithManifestError[] = 110 const char kNoPreviousBeginInstallWithManifestError[] =
107 "* does not match a previous call to beginInstallWithManifest3"; 111 "* does not match a previous call to beginInstallWithManifest3";
108 const char kUserCancelledError[] = "User cancelled install"; 112 const char kUserCancelledError[] = "User cancelled install";
109 113
110 // Helper to create a dictionary with login properties set from the appropriate 114 // Helper to create a dictionary with login properties set from the appropriate
(...skipping 11 matching lines...) Expand all
122 void EnableAppLauncher(base::Callback<void(bool)> callback) { 126 void EnableAppLauncher(base::Callback<void(bool)> callback) {
123 #if defined(OS_WIN) 127 #if defined(OS_WIN)
124 LOG(INFO) << "Enabling App Launcher via internal enable"; 128 LOG(INFO) << "Enabling App Launcher via internal enable";
125 AppListService::Get()->EnableAppList(); 129 AppListService::Get()->EnableAppList();
126 callback.Run(true); 130 callback.Run(true);
127 #else 131 #else
128 callback.Run(true); 132 callback.Run(true);
129 #endif 133 #endif
130 } 134 }
131 135
136 // We allow the web store to set a string containing login information when a
137 // purchase is made, so that when a user logs into sync with a different
138 // account we can recognize the situation. The Get function returns the login if
139 // there was previously stored data, or an empty string otherwise. The Set will
140 // overwrite any previous login.
141 std::string GetWebstoreLogin(Profile* profile) {
142 if (profile->GetPrefs()->HasPrefPath(kWebstoreLogin))
143 return profile->GetPrefs()->GetString(kWebstoreLogin);
144 return std::string();
145 }
146
147 void SetWebstoreLogin(Profile* profile, const std::string& login) {
148 profile->GetPrefs()->SetString(kWebstoreLogin, login);
149 }
150
132 } // namespace 151 } // namespace
133 152
134 // static 153 // static
135 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting( 154 void WebstorePrivateApi::SetWebstoreInstallerDelegateForTesting(
136 WebstoreInstaller::Delegate* delegate) { 155 WebstoreInstaller::Delegate* delegate) {
137 test_webstore_installer_delegate = delegate; 156 test_webstore_installer_delegate = delegate;
138 } 157 }
139 158
140 // static 159 // static
141 scoped_ptr<WebstoreInstaller::Approval> 160 scoped_ptr<WebstoreInstaller::Approval>
142 WebstorePrivateApi::PopApprovalForTesting( 161 WebstorePrivateApi::PopApprovalForTesting(
143 Profile* profile, const std::string& extension_id) { 162 Profile* profile, const std::string& extension_id) {
144 return g_pending_approvals.Get().PopApproval(profile, extension_id); 163 return g_pending_approvals.Get().PopApproval(profile, extension_id);
145 } 164 }
146 165
147 InstallBundleFunction::InstallBundleFunction() {} 166 InstallBundleFunction::InstallBundleFunction() {}
148 InstallBundleFunction::~InstallBundleFunction() {} 167 InstallBundleFunction::~InstallBundleFunction() {}
149 168
150 bool InstallBundleFunction::RunImpl() { 169 bool InstallBundleFunction::RunImpl() {
151 ListValue* extensions = NULL; 170 ListValue* extensions = NULL;
152 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions)); 171 EXTENSION_FUNCTION_VALIDATE(args_->GetList(0, &extensions));
153 172
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 LOG(ERROR) << "Error installing app launcher"; 601 LOG(ERROR) << "Error installing app launcher";
583 SendResponse(ok); 602 SendResponse(ok);
584 } 603 }
585 604
586 bool GetBrowserLoginFunction::RunImpl() { 605 bool GetBrowserLoginFunction::RunImpl() {
587 SetResult(CreateLoginResult(profile_->GetOriginalProfile())); 606 SetResult(CreateLoginResult(profile_->GetOriginalProfile()));
588 return true; 607 return true;
589 } 608 }
590 609
591 bool GetStoreLoginFunction::RunImpl() { 610 bool GetStoreLoginFunction::RunImpl() {
592 ExtensionService* service = 611 SetResult(Value::CreateStringValue(GetWebstoreLogin(profile_)));
593 extensions::ExtensionSystem::Get(profile_)->extension_service();
594 ExtensionPrefs* prefs = service->extension_prefs();
595 std::string login;
596 if (prefs->GetWebStoreLogin(&login)) {
597 SetResult(Value::CreateStringValue(login));
598 } else {
599 SetResult(Value::CreateStringValue(std::string()));
600 }
601 return true; 612 return true;
602 } 613 }
603 614
604 bool SetStoreLoginFunction::RunImpl() { 615 bool SetStoreLoginFunction::RunImpl() {
605 std::string login; 616 std::string login;
606 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); 617 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login));
607 ExtensionService* service = 618 SetWebstoreLogin(profile_, login);
608 extensions::ExtensionSystem::Get(profile_)->extension_service();
609 ExtensionPrefs* prefs = service->extension_prefs();
610 prefs->SetWebStoreLogin(login);
611 return true; 619 return true;
612 } 620 }
613 621
614 GetWebGLStatusFunction::GetWebGLStatusFunction() { 622 GetWebGLStatusFunction::GetWebGLStatusFunction() {
615 feature_checker_ = new GPUFeatureChecker( 623 feature_checker_ = new GPUFeatureChecker(
616 content::GPU_FEATURE_TYPE_WEBGL, 624 content::GPU_FEATURE_TYPE_WEBGL,
617 base::Bind(&GetWebGLStatusFunction::OnFeatureCheck, 625 base::Bind(&GetWebGLStatusFunction::OnFeatureCheck,
618 base::Unretained(this))); 626 base::Unretained(this)));
619 } 627 }
620 628
(...skipping 19 matching lines...) Expand all
640 &GetIsLauncherEnabledFunction::OnIsLauncherCheckCompleted, this)); 648 &GetIsLauncherEnabledFunction::OnIsLauncherCheckCompleted, this));
641 return true; 649 return true;
642 } 650 }
643 651
644 void GetIsLauncherEnabledFunction::OnIsLauncherCheckCompleted(bool is_enabled) { 652 void GetIsLauncherEnabledFunction::OnIsLauncherCheckCompleted(bool is_enabled) {
645 SetResult(Value::CreateBooleanValue(is_enabled)); 653 SetResult(Value::CreateBooleanValue(is_enabled));
646 SendResponse(true); 654 SendResponse(true);
647 } 655 }
648 656
649 } // namespace extensions 657 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698