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

Side by Side Diff: chrome/browser/ui/webui/identity_internals_ui.cc

Issue 2606293002: Remove ScopedVector from chrome/browser/ui. (Closed)
Patch Set: one last Created 3 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/webui/identity_internals_ui.h" 5 #include "chrome/browser/ui/webui/identity_internals_ui.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "chrome/browser/extensions/api/identity/identity_api.h" 17 #include "chrome/browser/extensions/api/identity/identity_api.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "chrome/grit/browser_resources.h" 20 #include "chrome/grit/browser_resources.h"
20 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
21 #include "content/public/browser/web_ui.h" 22 #include "content/public/browser/web_ui.h"
22 #include "content/public/browser/web_ui_controller.h" 23 #include "content/public/browser/web_ui_controller.h"
23 #include "content/public/browser/web_ui_data_source.h" 24 #include "content/public/browser/web_ui_data_source.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // to the caller using Javascript callback function 89 // to the caller using Javascript callback function
89 // |identity_internals.returnTokens()|. 90 // |identity_internals.returnTokens()|.
90 void GetInfoForAllTokens(const base::ListValue* args); 91 void GetInfoForAllTokens(const base::ListValue* args);
91 92
92 // Initiates revoking of the token, based on the extension ID and token 93 // Initiates revoking of the token, based on the extension ID and token
93 // passed as entries in the |args| list. Updates the caller of completion 94 // passed as entries in the |args| list. Updates the caller of completion
94 // using Javascript callback function |identity_internals.tokenRevokeDone()|. 95 // using Javascript callback function |identity_internals.tokenRevokeDone()|.
95 void RevokeToken(const base::ListValue* args); 96 void RevokeToken(const base::ListValue* args);
96 97
97 // A vector of token revokers that are currently revoking tokens. 98 // A vector of token revokers that are currently revoking tokens.
98 ScopedVector<IdentityInternalsTokenRevoker> token_revokers_; 99 std::vector<std::unique_ptr<IdentityInternalsTokenRevoker>> token_revokers_;
99 }; 100 };
100 101
101 // Handles the revoking of an access token and helps performing the clean up 102 // Handles the revoking of an access token and helps performing the clean up
102 // after it is revoked by holding information about the access token and related 103 // after it is revoked by holding information about the access token and related
103 // extension ID. 104 // extension ID.
104 class IdentityInternalsTokenRevoker : public GaiaAuthConsumer { 105 class IdentityInternalsTokenRevoker : public GaiaAuthConsumer {
105 public: 106 public:
106 // Revokes |access_token| from extension with |extension_id|. 107 // Revokes |access_token| from extension with |extension_id|.
107 // |profile| is required for its request context. |consumer| will be 108 // |profile| is required for its request context. |consumer| will be
108 // notified when revocation succeeds via |OnTokenRevokerDone()|. 109 // notified when revocation succeeds via |OnTokenRevokerDone()|.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 api->EraseCachedToken(token_revoker->extension_id(), 153 api->EraseCachedToken(token_revoker->extension_id(),
153 token_revoker->access_token()); 154 token_revoker->access_token());
154 155
155 // Update view about the token being removed. 156 // Update view about the token being removed.
156 base::ListValue result; 157 base::ListValue result;
157 result.AppendString(token_revoker->access_token()); 158 result.AppendString(token_revoker->access_token());
158 web_ui()->CallJavascriptFunctionUnsafe("identity_internals.tokenRevokeDone", 159 web_ui()->CallJavascriptFunctionUnsafe("identity_internals.tokenRevokeDone",
159 result); 160 result);
160 161
161 // Erase the revoker. 162 // Erase the revoker.
162 ScopedVector<IdentityInternalsTokenRevoker>::iterator iter = 163 auto iter = token_revokers_.begin();
163 std::find(token_revokers_.begin(), token_revokers_.end(), token_revoker); 164 for (; iter != token_revokers_.end(); ++iter) {
165 if (iter->get() == token_revoker)
166 break;
167 }
164 DCHECK(iter != token_revokers_.end()); 168 DCHECK(iter != token_revokers_.end());
165 token_revokers_.erase(iter); 169 token_revokers_.erase(iter);
Bernhard Bauer 2017/01/04 11:20:09 Can you move this inside the loop and then make it
Avi (use Gerrit) 2017/01/04 16:42:34 I can't switch to an object iterator because I can
166 } 170 }
167 171
168 const std::string IdentityInternalsUIMessageHandler::GetExtensionName( 172 const std::string IdentityInternalsUIMessageHandler::GetExtensionName(
169 const extensions::ExtensionTokenKey& token_cache_key) { 173 const extensions::ExtensionTokenKey& token_cache_key) {
170 const extensions::ExtensionRegistry* registry = 174 const extensions::ExtensionRegistry* registry =
171 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())); 175 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui()));
172 const extensions::Extension* extension = 176 const extensions::Extension* extension =
173 registry->enabled_extensions().GetByID(token_cache_key.extension_id); 177 registry->enabled_extensions().GetByID(token_cache_key.extension_id);
174 if (!extension) 178 if (!extension)
175 return std::string(); 179 return std::string();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 base::Bind(&IdentityInternalsUIMessageHandler::RevokeToken, 256 base::Bind(&IdentityInternalsUIMessageHandler::RevokeToken,
253 base::Unretained(this))); 257 base::Unretained(this)));
254 } 258 }
255 259
256 void IdentityInternalsUIMessageHandler::RevokeToken( 260 void IdentityInternalsUIMessageHandler::RevokeToken(
257 const base::ListValue* args) { 261 const base::ListValue* args) {
258 std::string extension_id; 262 std::string extension_id;
259 std::string access_token; 263 std::string access_token;
260 args->GetString(kRevokeTokenExtensionOffset, &extension_id); 264 args->GetString(kRevokeTokenExtensionOffset, &extension_id);
261 args->GetString(kRevokeTokenTokenOffset, &access_token); 265 args->GetString(kRevokeTokenTokenOffset, &access_token);
262 token_revokers_.push_back(new IdentityInternalsTokenRevoker( 266 token_revokers_.push_back(base::MakeUnique<IdentityInternalsTokenRevoker>(
263 extension_id, access_token, Profile::FromWebUI(web_ui()), this)); 267 extension_id, access_token, Profile::FromWebUI(web_ui()), this));
264 } 268 }
265 269
266 IdentityInternalsTokenRevoker::IdentityInternalsTokenRevoker( 270 IdentityInternalsTokenRevoker::IdentityInternalsTokenRevoker(
267 const std::string& extension_id, 271 const std::string& extension_id,
268 const std::string& access_token, 272 const std::string& access_token,
269 Profile* profile, 273 Profile* profile,
270 IdentityInternalsUIMessageHandler* consumer) 274 IdentityInternalsUIMessageHandler* consumer)
271 : fetcher_(this, GaiaConstants::kChromeSource, 275 : fetcher_(this, GaiaConstants::kChromeSource,
272 profile->GetRequestContext()), 276 profile->GetRequestContext()),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 html_source->AddResourcePath("identity_internals.js", 320 html_source->AddResourcePath("identity_internals.js",
317 IDR_IDENTITY_INTERNALS_JS); 321 IDR_IDENTITY_INTERNALS_JS);
318 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML); 322 html_source->SetDefaultResource(IDR_IDENTITY_INTERNALS_HTML);
319 323
320 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source); 324 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), html_source);
321 325
322 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler()); 326 web_ui->AddMessageHandler(new IdentityInternalsUIMessageHandler());
323 } 327 }
324 328
325 IdentityInternalsUI::~IdentityInternalsUI() {} 329 IdentityInternalsUI::~IdentityInternalsUI() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698