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

Side by Side Diff: chrome/browser/chromeos/extensions/install_limiter.cc

Issue 56833003: Use base::PostTaskAndReplyWithResults() in more places. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, fix clang error Created 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/chromeos/extensions/install_limiter.h" 5 #include "chrome/browser/chromeos/extensions/install_limiter.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/threading/sequenced_worker_pool.h" 11 #include "base/threading/sequenced_worker_pool.h"
12 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/chromeos/extensions/install_limiter_factory.h" 13 #include "chrome/browser/chromeos/extensions/install_limiter_factory.h"
14 #include "content/public/browser/browser_thread.h" 14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_details.h" 15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
17 17
18 using content::BrowserThread; 18 using content::BrowserThread;
19 19
20 namespace { 20 namespace {
21 21
22 // Gets the file size of |file| and stores it in |size| on the blocking pool. 22 int64 GetFileSizeOnBlockingPool(const base::FilePath& file) {
23 void GetFileSizeOnBlockingPool(const base::FilePath& file, int64* size) {
24 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 23 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
25 24
26 // Get file size. In case of error, sets 0 as file size to let the installer 25 // Get file size. In case of error, sets 0 as file size to let the installer
27 // run and fail. 26 // run and fail.
28 if (!file_util::GetFileSize(file, size)) 27 int64 size;
29 *size = 0; 28 return file_util::GetFileSize(file, &size) ? size : 0;
30 } 29 }
31 30
32 } // namespace 31 } // namespace
33 32
34 namespace extensions { 33 namespace extensions {
35 34
36 //////////////////////////////////////////////////////////////////////////////// 35 ////////////////////////////////////////////////////////////////////////////////
37 // InstallLimiter::DeferredInstall 36 // InstallLimiter::DeferredInstall
38 37
39 InstallLimiter::DeferredInstall::DeferredInstall( 38 InstallLimiter::DeferredInstall::DeferredInstall(
(...skipping 24 matching lines...) Expand all
64 } 63 }
65 64
66 void InstallLimiter::Add(const scoped_refptr<CrxInstaller>& installer, 65 void InstallLimiter::Add(const scoped_refptr<CrxInstaller>& installer,
67 const base::FilePath& path) { 66 const base::FilePath& path) {
68 // No deferred installs when disabled for test. 67 // No deferred installs when disabled for test.
69 if (disabled_for_test_) { 68 if (disabled_for_test_) {
70 installer->InstallCrx(path); 69 installer->InstallCrx(path);
71 return; 70 return;
72 } 71 }
73 72
74 int64* size = new int64(0); // Owned by reply callback below. 73 base::PostTaskAndReplyWithResult(
75 BrowserThread::PostBlockingPoolTaskAndReply( 74 BrowserThread::GetBlockingPool(),
76 FROM_HERE, 75 FROM_HERE,
77 base::Bind(&GetFileSizeOnBlockingPool, path, size), 76 base::Bind(&GetFileSizeOnBlockingPool, path),
78 base::Bind(&InstallLimiter::AddWithSize, AsWeakPtr(), 77 base::Bind(&InstallLimiter::AddWithSize, AsWeakPtr(), installer, path));
79 installer, path, base::Owned(size)));
80 } 78 }
81 79
82 void InstallLimiter::AddWithSize( 80 void InstallLimiter::AddWithSize(
83 const scoped_refptr<CrxInstaller>& installer, 81 const scoped_refptr<CrxInstaller>& installer,
84 const base::FilePath& path, 82 const base::FilePath& path,
85 int64* size) { 83 int64 size) {
86 const int64 kBigAppSizeThreshold = 1048576; // 1MB 84 const int64 kBigAppSizeThreshold = 1048576; // 1MB
87 85
88 if (*size <= kBigAppSizeThreshold) { 86 if (size <= kBigAppSizeThreshold) {
89 RunInstall(installer, path); 87 RunInstall(installer, path);
90 88
91 // Stop wait timer and let install notification drive deferred installs. 89 // Stop wait timer and let install notification drive deferred installs.
92 wait_timer_.Stop(); 90 wait_timer_.Stop();
93 return; 91 return;
94 } 92 }
95 93
96 deferred_installs_.push(DeferredInstall(installer, path)); 94 deferred_installs_.push(DeferredInstall(installer, path));
97 95
98 // When there are no running installs, wait a bit before running deferred 96 // When there are no running installs, wait a bit before running deferred
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 chrome::NOTIFICATION_CRX_INSTALLER_DONE, 133 chrome::NOTIFICATION_CRX_INSTALLER_DONE,
136 source); 134 source);
137 135
138 const scoped_refptr<CrxInstaller> installer = 136 const scoped_refptr<CrxInstaller> installer =
139 content::Source<extensions::CrxInstaller>(source).ptr(); 137 content::Source<extensions::CrxInstaller>(source).ptr();
140 running_installers_.erase(installer); 138 running_installers_.erase(installer);
141 CheckAndRunDeferrredInstalls(); 139 CheckAndRunDeferrredInstalls();
142 } 140 }
143 141
144 } // namespace extensions 142 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/install_limiter.h ('k') | chrome/browser/extensions/extension_protocols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698