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

Side by Side Diff: chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.cc

Issue 2704123007: mediaview: Fix ARC file system operation deferring. (Closed)
Patch Set: Addressed hidehiko's comments. Created 3 years, 10 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/arc/fileapi/arc_file_system_operation_runner.h " 5 #include "chrome/browser/chromeos/arc/fileapi/arc_file_system_operation_runner.h "
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/optional.h" 10 #include "base/optional.h"
(...skipping 11 matching lines...) Expand all
22 const char ArcFileSystemOperationRunner::kArcServiceName[] = 22 const char ArcFileSystemOperationRunner::kArcServiceName[] =
23 "arc::ArcFileSystemOperationRunner"; 23 "arc::ArcFileSystemOperationRunner";
24 24
25 // static 25 // static
26 std::unique_ptr<ArcFileSystemOperationRunner> 26 std::unique_ptr<ArcFileSystemOperationRunner>
27 ArcFileSystemOperationRunner::CreateForTesting( 27 ArcFileSystemOperationRunner::CreateForTesting(
28 ArcBridgeService* bridge_service) { 28 ArcBridgeService* bridge_service) {
29 // We can't use base::MakeUnique() here because we are calling a private 29 // We can't use base::MakeUnique() here because we are calling a private
30 // constructor. 30 // constructor.
31 return base::WrapUnique<ArcFileSystemOperationRunner>( 31 return base::WrapUnique<ArcFileSystemOperationRunner>(
32 new ArcFileSystemOperationRunner(bridge_service, false)); 32 new ArcFileSystemOperationRunner(bridge_service, nullptr, false));
33 } 33 }
34 34
35 ArcFileSystemOperationRunner::ArcFileSystemOperationRunner( 35 ArcFileSystemOperationRunner::ArcFileSystemOperationRunner(
36 ArcBridgeService* bridge_service) 36 ArcBridgeService* bridge_service,
37 : ArcFileSystemOperationRunner(bridge_service, true) {} 37 const Profile* profile)
38 : ArcFileSystemOperationRunner(bridge_service, profile, true) {
39 DCHECK(profile);
40 }
38 41
39 ArcFileSystemOperationRunner::ArcFileSystemOperationRunner( 42 ArcFileSystemOperationRunner::ArcFileSystemOperationRunner(
40 ArcBridgeService* bridge_service, 43 ArcBridgeService* bridge_service,
44 const Profile* profile,
41 bool observe_events) 45 bool observe_events)
42 : ArcService(bridge_service), 46 : ArcService(bridge_service),
47 profile_(profile),
43 observe_events_(observe_events), 48 observe_events_(observe_events),
44 weak_ptr_factory_(this) { 49 weak_ptr_factory_(this) {
45 DCHECK_CURRENTLY_ON(BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
46 51
47 if (observe_events_) { 52 if (observe_events_) {
48 ArcSessionManager::Get()->AddObserver(this); 53 ArcSessionManager::Get()->AddObserver(this);
49 arc_bridge_service()->file_system()->AddObserver(this); 54 arc_bridge_service()->file_system()->AddObserver(this);
50 OnStateChanged(); 55 OnStateChanged();
51 } 56 }
52 } 57 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 OnStateChanged(); 160 OnStateChanged();
156 } 161 }
157 162
158 void ArcFileSystemOperationRunner::OnInstanceClosed() { 163 void ArcFileSystemOperationRunner::OnInstanceClosed() {
159 DCHECK_CURRENTLY_ON(BrowserThread::UI); 164 DCHECK_CURRENTLY_ON(BrowserThread::UI);
160 OnStateChanged(); 165 OnStateChanged();
161 } 166 }
162 167
163 void ArcFileSystemOperationRunner::OnStateChanged() { 168 void ArcFileSystemOperationRunner::OnStateChanged() {
164 DCHECK_CURRENTLY_ON(BrowserThread::UI); 169 DCHECK_CURRENTLY_ON(BrowserThread::UI);
165 // TODO(hidehiko): Revisit the condition, when ARC is running without 170 SetShouldDefer(IsArcPlayStoreEnabledForProfile(profile_) &&
166 // profile. 171 !arc_bridge_service()->file_system()->has_instance());
167 SetShouldDefer(
168 IsArcPlayStoreEnabledForProfile(ArcSessionManager::Get()->profile()) &&
169 !arc_bridge_service()->file_system()->has_instance());
170 } 172 }
171 173
172 void ArcFileSystemOperationRunner::SetShouldDefer(bool should_defer) { 174 void ArcFileSystemOperationRunner::SetShouldDefer(bool should_defer) {
173 DCHECK_CURRENTLY_ON(BrowserThread::UI); 175 DCHECK_CURRENTLY_ON(BrowserThread::UI);
174 176
175 should_defer_ = should_defer; 177 should_defer_ = should_defer;
176 178
177 if (should_defer_) 179 if (should_defer_)
178 return; 180 return;
179 181
180 // Run deferred operations. 182 // Run deferred operations.
181 std::vector<base::Closure> deferred_operations; 183 std::vector<base::Closure> deferred_operations;
182 deferred_operations.swap(deferred_operations_); 184 deferred_operations.swap(deferred_operations_);
183 for (const base::Closure& operation : deferred_operations) { 185 for (const base::Closure& operation : deferred_operations) {
184 operation.Run(); 186 operation.Run();
185 } 187 }
186 188
187 // No deferred operations should be left at this point. 189 // No deferred operations should be left at this point.
188 DCHECK(deferred_operations_.empty()); 190 DCHECK(deferred_operations_.empty());
189 } 191 }
190 192
191 } // namespace arc 193 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698