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

Side by Side Diff: chrome/browser/extensions/api/history/history_api.cc

Issue 257333002: Drive extension functions from ExtensionFunction::Run. The (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 6 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) 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/history/history_api.h" 5 #include "chrome/browser/extensions/api/history/history_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 return (seconds_from_epoch == 0) ? 263 return (seconds_from_epoch == 0) ?
264 base::Time::UnixEpoch() : base::Time::FromDoubleT(seconds_from_epoch); 264 base::Time::UnixEpoch() : base::Time::FromDoubleT(seconds_from_epoch);
265 } 265 }
266 266
267 HistoryFunctionWithCallback::HistoryFunctionWithCallback() { 267 HistoryFunctionWithCallback::HistoryFunctionWithCallback() {
268 } 268 }
269 269
270 HistoryFunctionWithCallback::~HistoryFunctionWithCallback() { 270 HistoryFunctionWithCallback::~HistoryFunctionWithCallback() {
271 } 271 }
272 272
273 bool HistoryFunctionWithCallback::RunImpl() { 273 bool HistoryFunctionWithCallback::RunAsync() {
274 AddRef(); // Balanced in SendAysncRepose() and below. 274 AddRef(); // Balanced in SendAysncRepose() and below.
275 bool retval = RunAsyncImpl(); 275 bool retval = RunAsyncImpl();
276 if (false == retval) 276 if (false == retval)
277 Release(); 277 Release();
278 return retval; 278 return retval;
279 } 279 }
280 280
281 void HistoryFunctionWithCallback::SendAsyncResponse() { 281 void HistoryFunctionWithCallback::SendAsyncResponse() {
282 base::MessageLoop::current()->PostTask( 282 base::MessageLoop::current()->PostTask(
283 FROM_HERE, 283 FROM_HERE,
284 base::Bind(&HistoryFunctionWithCallback::SendResponseToCallback, this)); 284 base::Bind(&HistoryFunctionWithCallback::SendResponseToCallback, this));
285 } 285 }
286 286
287 void HistoryFunctionWithCallback::SendResponseToCallback() { 287 void HistoryFunctionWithCallback::SendResponseToCallback() {
288 SendResponse(true); 288 SendResponse(true);
289 Release(); // Balanced in RunImpl(). 289 Release(); // Balanced in RunAsync().
290 } 290 }
291 291
292 bool HistoryGetVisitsFunction::RunAsyncImpl() { 292 bool HistoryGetVisitsFunction::RunAsyncImpl() {
293 scoped_ptr<GetVisits::Params> params(GetVisits::Params::Create(*args_)); 293 scoped_ptr<GetVisits::Params> params(GetVisits::Params::Create(*args_));
294 EXTENSION_FUNCTION_VALIDATE(params.get()); 294 EXTENSION_FUNCTION_VALIDATE(params.get());
295 295
296 GURL url; 296 GURL url;
297 if (!ValidateUrl(params->details.url, &url)) 297 if (!ValidateUrl(params->details.url, &url))
298 return false; 298 return false;
299 299
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 iterator != results->end(); 363 iterator != results->end();
364 ++iterator) { 364 ++iterator) {
365 history_item_vec.push_back(make_linked_ptr( 365 history_item_vec.push_back(make_linked_ptr(
366 GetHistoryItem(**iterator).release())); 366 GetHistoryItem(**iterator).release()));
367 } 367 }
368 } 368 }
369 results_ = Search::Results::Create(history_item_vec); 369 results_ = Search::Results::Create(history_item_vec);
370 SendAsyncResponse(); 370 SendAsyncResponse();
371 } 371 }
372 372
373 bool HistoryAddUrlFunction::RunImpl() { 373 bool HistoryAddUrlFunction::RunAsync() {
374 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_)); 374 scoped_ptr<AddUrl::Params> params(AddUrl::Params::Create(*args_));
375 EXTENSION_FUNCTION_VALIDATE(params.get()); 375 EXTENSION_FUNCTION_VALIDATE(params.get());
376 376
377 GURL url; 377 GURL url;
378 if (!ValidateUrl(params->details.url, &url)) 378 if (!ValidateUrl(params->details.url, &url))
379 return false; 379 return false;
380 380
381 HistoryService* hs = HistoryServiceFactory::GetForProfile( 381 HistoryService* hs = HistoryServiceFactory::GetForProfile(
382 GetProfile(), Profile::EXPLICIT_ACCESS); 382 GetProfile(), Profile::EXPLICIT_ACCESS);
383 hs->AddPage(url, base::Time::Now(), history::SOURCE_EXTENSION); 383 hs->AddPage(url, base::Time::Now(), history::SOURCE_EXTENSION);
384 384
385 SendResponse(true); 385 SendResponse(true);
386 return true; 386 return true;
387 } 387 }
388 388
389 bool HistoryDeleteUrlFunction::RunImpl() { 389 bool HistoryDeleteUrlFunction::RunAsync() {
390 scoped_ptr<DeleteUrl::Params> params(DeleteUrl::Params::Create(*args_)); 390 scoped_ptr<DeleteUrl::Params> params(DeleteUrl::Params::Create(*args_));
391 EXTENSION_FUNCTION_VALIDATE(params.get()); 391 EXTENSION_FUNCTION_VALIDATE(params.get());
392 392
393 if (!VerifyDeleteAllowed()) 393 if (!VerifyDeleteAllowed())
394 return false; 394 return false;
395 395
396 GURL url; 396 GURL url;
397 if (!ValidateUrl(params->details.url, &url)) 397 if (!ValidateUrl(params->details.url, &url))
398 return false; 398 return false;
399 399
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } 475 }
476 476
477 return true; 477 return true;
478 } 478 }
479 479
480 void HistoryDeleteAllFunction::DeleteComplete() { 480 void HistoryDeleteAllFunction::DeleteComplete() {
481 SendAsyncResponse(); 481 SendAsyncResponse();
482 } 482 }
483 483
484 } // namespace extensions 484 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/history/history_api.h ('k') | chrome/browser/extensions/api/identity/identity_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698