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

Side by Side Diff: chrome/browser/component_updater/component_updater_service.cc

Issue 8500008: base::Bind() conversion for ComponentUpdaterService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/component_updater/component_updater_service.h" 5 #include "chrome/browser/component_updater/component_updater_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/at_exit.h" 10 #include "base/at_exit.h"
11 #include "base/bind.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 17 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 18 #include "base/string_util.h"
18 #include "base/stringprintf.h" 19 #include "base/stringprintf.h"
19 #include "base/timer.h" 20 #include "base/timer.h"
20 #include "chrome/browser/browser_process.h" 21 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/component_updater/component_unpacker.h" 22 #include "chrome/browser/component_updater/component_unpacker.h"
22 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_utility_messages.h" 24 #include "chrome/common/chrome_utility_messages.h"
24 #include "chrome/common/chrome_version_info.h" 25 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/extensions/extension.h" 26 #include "chrome/common/extensions/extension.h"
26 #include "content/browser/utility_process_host.h" 27 #include "content/browser/utility_process_host.h"
27 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
28 #include "content/public/common/url_fetcher_delegate.h" 29 #include "content/public/common/url_fetcher_delegate.h"
29 #include "content/public/common/url_fetcher.h" 30 #include "content/public/common/url_fetcher.h"
30 #include "googleurl/src/gurl.h" 31 #include "googleurl/src/gurl.h"
31 #include "net/base/escape.h" 32 #include "net/base/escape.h"
32 #include "net/base/load_flags.h" 33 #include "net/base/load_flags.h"
33 34
34 using content::BrowserThread; 35 using content::BrowserThread;
35 36
37 // The component updater is designed to live until process shutdown, so
38 // base::Bind() calls are not refcounted.
39
36 namespace { 40 namespace {
37 // Extends an omaha compatible update check url |query| string. Does 41 // Extends an omaha compatible update check url |query| string. Does
38 // not mutate the string if it would be longer than |limit| chars. 42 // not mutate the string if it would be longer than |limit| chars.
39 bool AddQueryString(std::string id, std::string version, 43 bool AddQueryString(std::string id, std::string version,
40 size_t limit, std::string* query) { 44 size_t limit, std::string* query) {
41 std::string additional = 45 std::string additional =
42 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str()); 46 base::StringPrintf("id=%s&v=%s&uc", id.c_str(), version.c_str());
43 additional = "x=" + net::EscapeQueryParamValue(additional, true); 47 additional = "x=" + net::EscapeQueryParamValue(additional, true);
44 if ((additional.size() + query->size() + 1) > limit) 48 if ((additional.size() + query->size() + 1) > limit)
45 return false; 49 return false;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 320
317 base::OneShotTimer<CrxUpdateService> timer_; 321 base::OneShotTimer<CrxUpdateService> timer_;
318 322
319 Version chrome_version_; 323 Version chrome_version_;
320 324
321 bool running_; 325 bool running_;
322 326
323 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService); 327 DISALLOW_COPY_AND_ASSIGN(CrxUpdateService);
324 }; 328 };
325 329
326 // The component updater is designed to live until process shutdown, besides
327 // we can't be refcounted because we are a singleton.
328 DISABLE_RUNNABLE_METHOD_REFCOUNT(CrxUpdateService);
329
330 ////////////////////////////////////////////////////////////////////////////// 330 //////////////////////////////////////////////////////////////////////////////
331 331
332 CrxUpdateService::CrxUpdateService( 332 CrxUpdateService::CrxUpdateService(
333 ComponentUpdateService::Configurator* config) 333 ComponentUpdateService::Configurator* config)
334 : config_(config), 334 : config_(config),
335 chrome_version_(chrome::VersionInfo().Version()), 335 chrome_version_(chrome::VersionInfo().Version()),
336 running_(false) { 336 running_(false) {
337 } 337 }
338 338
339 CrxUpdateService::~CrxUpdateService() { 339 CrxUpdateService::~CrxUpdateService() {
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 CrxUpdateItem::kUpdating); 687 CrxUpdateItem::kUpdating);
688 DCHECK_EQ(count, 1ul); 688 DCHECK_EQ(count, 1ul);
689 url_fetcher_.reset(); 689 url_fetcher_.reset();
690 690
691 content::NotificationService::current()->Notify( 691 content::NotificationService::current()->Notify(
692 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, 692 chrome::NOTIFICATION_COMPONENT_UPDATE_READY,
693 content::Source<std::string>(&context->id), 693 content::Source<std::string>(&context->id),
694 content::NotificationService::NoDetails()); 694 content::NotificationService::NoDetails());
695 695
696 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, 696 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
697 NewRunnableMethod(this, &CrxUpdateService::Install, 697 base::Bind(&CrxUpdateService::Install,
698 context, 698 base::Unretained(this),
asargent_no_longer_on_chrome 2011/11/21 18:00:16 optional suggestion: add comment near the base:Unr
699 temp_crx_path), 699 context,
700 temp_crx_path),
700 config_->StepDelay()); 701 config_->StepDelay());
701 } 702 }
702 } 703 }
703 704
704 // Install consists of digital signature verification, unpacking and then 705 // Install consists of digital signature verification, unpacking and then
705 // calling the component specific installer. All that is handled by the 706 // calling the component specific installer. All that is handled by the
706 // |unpacker|. If there is an error this function is in charge of deleting 707 // |unpacker|. If there is an error this function is in charge of deleting
707 // the files created. 708 // the files created.
708 void CrxUpdateService::Install(const CRXContext* context, 709 void CrxUpdateService::Install(const CRXContext* context,
709 const FilePath& crx_path) { 710 const FilePath& crx_path) {
710 // This function owns the |crx_path| and the |context| object. 711 // This function owns the |crx_path| and the |context| object.
711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
712 ComponentUnpacker 713 ComponentUnpacker
713 unpacker(context->pk_hash, crx_path, context->installer); 714 unpacker(context->pk_hash, crx_path, context->installer);
714 if (!file_util::Delete(crx_path, false)) { 715 if (!file_util::Delete(crx_path, false)) {
715 NOTREACHED() << crx_path.value(); 716 NOTREACHED() << crx_path.value();
716 } 717 }
717 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE, 718 BrowserThread::PostDelayedTask(BrowserThread::UI, FROM_HERE,
718 NewRunnableMethod(this, &CrxUpdateService::DoneInstalling, 719 base::Bind(&CrxUpdateService::DoneInstalling, base::Unretained(this),
asargent_no_longer_on_chrome 2011/11/21 18:00:16 same suggestion here
719 context->id, unpacker.error()), 720 context->id, unpacker.error()),
720 config_->StepDelay()); 721 config_->StepDelay());
721 delete context; 722 delete context;
722 } 723 }
723 724
724 // Installation has been completed. Adjust the component status and 725 // Installation has been completed. Adjust the component status and
725 // schedule the next check. 726 // schedule the next check.
726 void CrxUpdateService::DoneInstalling(const std::string& component_id, 727 void CrxUpdateService::DoneInstalling(const std::string& component_id,
727 ComponentUnpacker::Error error) { 728 ComponentUnpacker::Error error) {
728 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 729 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
729 730
(...skipping 20 matching lines...) Expand all
750 ScheduleNextRun(false); 751 ScheduleNextRun(false);
751 } 752 }
752 753
753 // The component update factory. Using the component updater as a singleton 754 // The component update factory. Using the component updater as a singleton
754 // is the job of the browser process. 755 // is the job of the browser process.
755 ComponentUpdateService* ComponentUpdateServiceFactory( 756 ComponentUpdateService* ComponentUpdateServiceFactory(
756 ComponentUpdateService::Configurator* config) { 757 ComponentUpdateService::Configurator* config) {
757 DCHECK(config); 758 DCHECK(config);
758 return new CrxUpdateService(config); 759 return new CrxUpdateService(config);
759 } 760 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698