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/extensions/api/identity/identity_api.h" | 5 #include "chrome/browser/extensions/api/identity/identity_api.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
9 #include <set> | 10 #include <set> |
10 #include <string> | 11 #include <string> |
11 #include <utility> | 12 #include <utility> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
17 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 286 |
286 ExtensionFunction::ResponseAction IdentityGetAccountsFunction::Run() { | 287 ExtensionFunction::ResponseAction IdentityGetAccountsFunction::Run() { |
287 if (GetProfile()->IsOffTheRecord()) { | 288 if (GetProfile()->IsOffTheRecord()) { |
288 return RespondNow(Error(identity_constants::kOffTheRecord)); | 289 return RespondNow(Error(identity_constants::kOffTheRecord)); |
289 } | 290 } |
290 | 291 |
291 std::vector<std::string> gaia_ids = | 292 std::vector<std::string> gaia_ids = |
292 IdentityAPI::GetFactoryInstance()->Get(GetProfile())->GetAccounts(); | 293 IdentityAPI::GetFactoryInstance()->Get(GetProfile())->GetAccounts(); |
293 DCHECK(gaia_ids.size() < 2 || switches::IsExtensionsMultiAccount()); | 294 DCHECK(gaia_ids.size() < 2 || switches::IsExtensionsMultiAccount()); |
294 | 295 |
295 base::ListValue* infos = new base::ListValue(); | 296 std::unique_ptr<base::ListValue> infos(new base::ListValue()); |
296 | 297 |
297 for (std::vector<std::string>::const_iterator it = gaia_ids.begin(); | 298 for (std::vector<std::string>::const_iterator it = gaia_ids.begin(); |
298 it != gaia_ids.end(); | 299 it != gaia_ids.end(); |
299 ++it) { | 300 ++it) { |
300 api::identity::AccountInfo account_info; | 301 api::identity::AccountInfo account_info; |
301 account_info.id = *it; | 302 account_info.id = *it; |
302 infos->Append(account_info.ToValue().release()); | 303 infos->Append(account_info.ToValue().release()); |
303 } | 304 } |
304 | 305 |
305 return RespondNow(OneArgument(infos)); | 306 return RespondNow(OneArgument(std::move(infos))); |
306 } | 307 } |
307 | 308 |
308 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() | 309 IdentityGetAuthTokenFunction::IdentityGetAuthTokenFunction() |
309 : OAuth2TokenService::Consumer("extensions_identity_api"), | 310 : OAuth2TokenService::Consumer("extensions_identity_api"), |
310 interactive_(false), | 311 interactive_(false), |
311 should_prompt_for_scopes_(false), | 312 should_prompt_for_scopes_(false), |
312 should_prompt_for_signin_(false) { | 313 should_prompt_for_signin_(false) { |
313 } | 314 } |
314 | 315 |
315 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() { | 316 IdentityGetAuthTokenFunction::~IdentityGetAuthTokenFunction() { |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 AccountInfo account = | 911 AccountInfo account = |
911 AccountTrackerServiceFactory::GetForProfile(GetProfile()) | 912 AccountTrackerServiceFactory::GetForProfile(GetProfile()) |
912 ->GetAccountInfo(GetPrimaryAccountId(GetProfile())); | 913 ->GetAccountInfo(GetPrimaryAccountId(GetProfile())); |
913 api::identity::ProfileUserInfo profile_user_info; | 914 api::identity::ProfileUserInfo profile_user_info; |
914 if (extension()->permissions_data()->HasAPIPermission( | 915 if (extension()->permissions_data()->HasAPIPermission( |
915 APIPermission::kIdentityEmail)) { | 916 APIPermission::kIdentityEmail)) { |
916 profile_user_info.email = account.email; | 917 profile_user_info.email = account.email; |
917 profile_user_info.id = account.gaia; | 918 profile_user_info.id = account.gaia; |
918 } | 919 } |
919 | 920 |
920 return RespondNow(OneArgument(profile_user_info.ToValue().release())); | 921 return RespondNow(OneArgument(profile_user_info.ToValue())); |
921 } | 922 } |
922 | 923 |
923 IdentityRemoveCachedAuthTokenFunction::IdentityRemoveCachedAuthTokenFunction() { | 924 IdentityRemoveCachedAuthTokenFunction::IdentityRemoveCachedAuthTokenFunction() { |
924 } | 925 } |
925 | 926 |
926 IdentityRemoveCachedAuthTokenFunction:: | 927 IdentityRemoveCachedAuthTokenFunction:: |
927 ~IdentityRemoveCachedAuthTokenFunction() { | 928 ~IdentityRemoveCachedAuthTokenFunction() { |
928 } | 929 } |
929 | 930 |
930 bool IdentityRemoveCachedAuthTokenFunction::RunSync() { | 931 bool IdentityRemoveCachedAuthTokenFunction::RunSync() { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { | 1016 if (redirect_url.GetWithEmptyPath() == final_url_prefix_) { |
1016 SetResult(base::MakeUnique<base::StringValue>(redirect_url.spec())); | 1017 SetResult(base::MakeUnique<base::StringValue>(redirect_url.spec())); |
1017 SendResponse(true); | 1018 SendResponse(true); |
1018 if (auth_flow_) | 1019 if (auth_flow_) |
1019 auth_flow_.release()->DetachDelegateAndDelete(); | 1020 auth_flow_.release()->DetachDelegateAndDelete(); |
1020 Release(); // Balanced in RunAsync. | 1021 Release(); // Balanced in RunAsync. |
1021 } | 1022 } |
1022 } | 1023 } |
1023 | 1024 |
1024 } // namespace extensions | 1025 } // namespace extensions |
OLD | NEW |