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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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) 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/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_util.h" 17 #include "base/string_util.h"
18 #include "base/stringprintf.h" 18 #include "base/stringprintf.h"
19 #include "base/timer.h" 19 #include "base/timer.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/component_updater/component_unpacker.h" 21 #include "chrome/browser/component_updater/component_unpacker.h"
22 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_utility_messages.h" 23 #include "chrome/common/chrome_utility_messages.h"
24 #include "chrome/common/chrome_version_info.h" 24 #include "chrome/common/chrome_version_info.h"
25 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
26 #include "content/browser/utility_process_host.h" 26 #include "content/browser/utility_process_host.h"
27 #include "content/common/net/url_fetcher.h" 27 #include "content/common/net/url_fetcher.h"
28 #include "content/common/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "googleurl/src/gurl.h" 29 #include "googleurl/src/gurl.h"
30 #include "net/base/escape.h" 30 #include "net/base/escape.h"
31 #include "net/base/load_flags.h" 31 #include "net/base/load_flags.h"
32 32
33 namespace { 33 namespace {
34 // Extends an omaha compatible update check url |query| string. Does 34 // Extends an omaha compatible update check url |query| string. Does
35 // not mutate the string if it would be longer than |limit| chars. 35 // not mutate the string if it would be longer than |limit| chars.
36 bool AddQueryString(std::string id, std::string version, 36 bool AddQueryString(std::string id, std::string version,
37 size_t limit, std::string* query) { 37 size_t limit, std::string* query) {
38 std::string additional = 38 std::string additional =
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 340 }
341 341
342 ComponentUpdateService::Status CrxUpdateService::Start() { 342 ComponentUpdateService::Status CrxUpdateService::Start() {
343 // Note that RegisterComponent will call Start() when the first 343 // Note that RegisterComponent will call Start() when the first
344 // component is registered, so it can be called twice. This way 344 // component is registered, so it can be called twice. This way
345 // we avoid scheduling the timer if there is no work to do. 345 // we avoid scheduling the timer if there is no work to do.
346 running_ = true; 346 running_ = true;
347 if (work_items_.empty()) 347 if (work_items_.empty())
348 return kOk; 348 return kOk;
349 349
350 NotificationService::current()->Notify( 350 content::NotificationService::current()->Notify(
351 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED, 351 chrome::NOTIFICATION_COMPONENT_UPDATER_STARTED,
352 content::Source<ComponentUpdateService>(this), 352 content::Source<ComponentUpdateService>(this),
353 NotificationService::NoDetails()); 353 content::NotificationService::NoDetails());
354 354
355 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->InitialDelay()), 355 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(config_->InitialDelay()),
356 this, &CrxUpdateService::ProcessPendingItems); 356 this, &CrxUpdateService::ProcessPendingItems);
357 return kOk; 357 return kOk;
358 } 358 }
359 359
360 // Stop the main check + update loop. In flight operations will be 360 // Stop the main check + update loop. In flight operations will be
361 // completed. 361 // completed.
362 ComponentUpdateService::Status CrxUpdateService::Stop() { 362 ComponentUpdateService::Status CrxUpdateService::Stop() {
363 running_ = false; 363 running_ = false;
(...skipping 10 matching lines...) Expand all
374 CHECK(!timer_.IsRunning()); 374 CHECK(!timer_.IsRunning());
375 // It could be the case that Stop() had been called while a url request 375 // It could be the case that Stop() had been called while a url request
376 // or unpacking was in flight, if so we arrive here but |running_| is 376 // or unpacking was in flight, if so we arrive here but |running_| is
377 // false. In that case do not loop again. 377 // false. In that case do not loop again.
378 if (!running_) 378 if (!running_)
379 return; 379 return;
380 380
381 int64 delay = step_delay ? config_->StepDelay() : config_->NextCheckDelay(); 381 int64 delay = step_delay ? config_->StepDelay() : config_->NextCheckDelay();
382 382
383 if (!step_delay) { 383 if (!step_delay) {
384 NotificationService::current()->Notify( 384 content::NotificationService::current()->Notify(
385 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING, 385 chrome::NOTIFICATION_COMPONENT_UPDATER_SLEEPING,
386 content::Source<ComponentUpdateService>(this), 386 content::Source<ComponentUpdateService>(this),
387 NotificationService::NoDetails()); 387 content::NotificationService::NoDetails());
388 // Zero is only used for unit tests. 388 // Zero is only used for unit tests.
389 if (0 == delay) 389 if (0 == delay)
390 return; 390 return;
391 } 391 }
392 392
393 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay), 393 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(delay),
394 this, &CrxUpdateService::ProcessPendingItems); 394 this, &CrxUpdateService::ProcessPendingItems);
395 } 395 }
396 396
397 // Given a extension-like component id, find the associated component. 397 // Given a extension-like component id, find the associated component.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 continue; 627 continue;
628 } 628 }
629 } 629 }
630 // All test passed. Queue an upgrade for this component and fire the 630 // All test passed. Queue an upgrade for this component and fire the
631 // notifications. 631 // notifications.
632 crx->crx_url = it->crx_url; 632 crx->crx_url = it->crx_url;
633 crx->status = CrxUpdateItem::kCanUpdate; 633 crx->status = CrxUpdateItem::kCanUpdate;
634 crx->next_version = Version(it->version); 634 crx->next_version = Version(it->version);
635 ++update_pending; 635 ++update_pending;
636 636
637 NotificationService::current()->Notify( 637 content::NotificationService::current()->Notify(
638 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND, 638 chrome::NOTIFICATION_COMPONENT_UPDATE_FOUND,
639 content::Source<std::string>(&crx->id), 639 content::Source<std::string>(&crx->id),
640 NotificationService::NoDetails()); 640 content::NotificationService::NoDetails());
641 } 641 }
642 642
643 // All the components that are not mentioned in the manifest we 643 // All the components that are not mentioned in the manifest we
644 // consider them up to date. 644 // consider them up to date.
645 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate); 645 ChangeItemStatus(CrxUpdateItem::kChecking, CrxUpdateItem::kUpToDate);
646 646
647 // If there are updates pending we do a short wait. 647 // If there are updates pending we do a short wait.
648 ScheduleNextRun(update_pending ? true : false); 648 ScheduleNextRun(update_pending ? true : false);
649 } 649 }
650 650
(...skipping 23 matching lines...) Expand all
674 url_fetcher_.reset(); 674 url_fetcher_.reset();
675 ScheduleNextRun(false); 675 ScheduleNextRun(false);
676 } else { 676 } else {
677 FilePath temp_crx_path; 677 FilePath temp_crx_path;
678 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path)); 678 CHECK(source->GetResponseAsFilePath(true, &temp_crx_path));
679 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading, 679 size_t count = ChangeItemStatus(CrxUpdateItem::kDownloading,
680 CrxUpdateItem::kUpdating); 680 CrxUpdateItem::kUpdating);
681 DCHECK_EQ(count, 1ul); 681 DCHECK_EQ(count, 1ul);
682 url_fetcher_.reset(); 682 url_fetcher_.reset();
683 683
684 NotificationService::current()->Notify( 684 content::NotificationService::current()->Notify(
685 chrome::NOTIFICATION_COMPONENT_UPDATE_READY, 685 chrome::NOTIFICATION_COMPONENT_UPDATE_READY,
686 content::Source<std::string>(&context->id), 686 content::Source<std::string>(&context->id),
687 NotificationService::NoDetails()); 687 content::NotificationService::NoDetails());
688 688
689 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE, 689 BrowserThread::PostDelayedTask(BrowserThread::FILE, FROM_HERE,
690 NewRunnableMethod(this, &CrxUpdateService::Install, 690 NewRunnableMethod(this, &CrxUpdateService::Install,
691 context, 691 context,
692 temp_crx_path), 692 temp_crx_path),
693 config_->StepDelay()); 693 config_->StepDelay());
694 } 694 }
695 } 695 }
696 696
697 // Install consists of digital signature verification, unpacking and then 697 // Install consists of digital signature verification, unpacking and then
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 ScheduleNextRun(false); 743 ScheduleNextRun(false);
744 } 744 }
745 745
746 // The component update factory. Using the component updater as a singleton 746 // The component update factory. Using the component updater as a singleton
747 // is the job of the browser process. 747 // is the job of the browser process.
748 ComponentUpdateService* ComponentUpdateServiceFactory( 748 ComponentUpdateService* ComponentUpdateServiceFactory(
749 ComponentUpdateService::Configurator* config) { 749 ComponentUpdateService::Configurator* config) {
750 DCHECK(config); 750 DCHECK(config);
751 return new CrxUpdateService(config); 751 return new CrxUpdateService(config);
752 } 752 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/wm_ipc.cc ('k') | chrome/browser/component_updater/component_updater_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698