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

Side by Side Diff: chrome/browser/chromeos/extensions/file_manager/drive_test_util.cc

Issue 13866050: drive: Introduce DriveSystemServiceObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 8 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) 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chrome/browser/chromeos/drive/drive_file_system.h" 8 #include "chrome/browser/chromeos/drive/drive_file_system.h"
9 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" 9 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h"
10 #include "chrome/browser/chromeos/drive/drive_system_service.h" 10 #include "chrome/browser/chromeos/drive/drive_system_service.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
13 #include "webkit/fileapi/external_mount_points.h" 13 #include "webkit/fileapi/external_mount_points.h"
14 14
15 namespace drive_test_util { 15 namespace drive_test_util {
16 16
17 namespace { 17 namespace {
18 18
19 const char kDriveMountPointName[] = "drive"; 19 const char kDriveMountPointName[] = "drive";
20 20
21 // Helper class used to wait for |OnFileSystemMounted| event from a drive file 21 // Helper class used to wait for |OnFileSystemMounted| event from a drive file
22 // system. 22 // system.
23 class DriveMountPointWaiter : public drive::DriveFileSystemObserver { 23 class DriveMountPointWaiter : public drive::DriveSystemServiceObserver {
24 public: 24 public:
25 explicit DriveMountPointWaiter(drive::DriveFileSystemInterface* file_system) 25 explicit DriveMountPointWaiter(drive::DriveSystemService* system_service)
26 : file_system_(file_system) { 26 : system_service_(system_service) {
27 file_system_->AddObserver(this); 27 system_service_->AddObserver(this);
28 } 28 }
29 29
30 virtual ~DriveMountPointWaiter() { 30 virtual ~DriveMountPointWaiter() {
31 file_system_->RemoveObserver(this); 31 system_service_->RemoveObserver(this);
32 } 32 }
33 33
34 // DriveFileSystemObserver override. 34 // DriveSystemServiceObserver override.
35 virtual void OnFileSystemMounted() OVERRIDE { 35 virtual void OnFileSystemMounted() OVERRIDE {
36 // Note that it is OK for |run_loop_.Quit| to be called before 36 // Note that it is OK for |run_loop_.Quit| to be called before
37 // |run_loop_.Run|. In this case |Run| will return immediately. 37 // |run_loop_.Run|. In this case |Run| will return immediately.
38 run_loop_.Quit(); 38 run_loop_.Quit();
39 } 39 }
40 40
41 // Runs loop until the file_system_ gets mounted. 41 // Runs loop until the file system is mounted.
42 void Wait() { 42 void Wait() {
43 run_loop_.Run(); 43 run_loop_.Run();
44 } 44 }
45 45
46 private: 46 private:
47 drive::DriveFileSystemInterface* file_system_; 47 drive::DriveSystemService* system_service_;
48 base::RunLoop run_loop_; 48 base::RunLoop run_loop_;
49 }; 49 };
50 50
51 } // namespace 51 } // namespace
52 52
53 void WaitUntilDriveMountPointIsAdded(Profile* profile) { 53 void WaitUntilDriveMountPointIsAdded(Profile* profile) {
54 DCHECK(profile); 54 DCHECK(profile);
55 55
56 // Drive mount point is added by the browser when the drive system service 56 // Drive mount point is added by the browser when the drive system service
57 // is first initialized. It is done asynchronously after some other parts of 57 // is first initialized. It is done asynchronously after some other parts of
58 // the service are initialized (e.g. resource metadata and cache), thus racy 58 // the service are initialized (e.g. resource metadata and cache), thus racy
59 // with the test start. To handle this raciness, the test verifies that 59 // with the test start. To handle this raciness, the test verifies that
60 // drive mount point is added before continuing. If this is not the case, 60 // drive mount point is added before continuing. If this is not the case,
61 // drive file system is observed for FileSystemMounted event (by 61 // drive file system is observed for FileSystemMounted event (by
62 // |mount_point_waiter|) and test continues once the event is encountered. 62 // |mount_point_waiter|) and test continues once the event is encountered.
63 drive::DriveSystemService* system_service = 63 drive::DriveSystemService* system_service =
64 drive::DriveSystemServiceFactory::FindForProfileRegardlessOfStates( 64 drive::DriveSystemServiceFactory::FindForProfileRegardlessOfStates(
65 profile); 65 profile);
66 DCHECK(system_service && system_service->file_system()); 66 DCHECK(system_service);
67 67
68 DriveMountPointWaiter mount_point_waiter(system_service->file_system()); 68 DriveMountPointWaiter mount_point_waiter(system_service);
69 69
70 base::FilePath ignored; 70 base::FilePath ignored;
71 // GetRegisteredPath succeeds iff the mount point exists. 71 // GetRegisteredPath succeeds iff the mount point exists.
72 if (!content::BrowserContext::GetMountPoints(profile)-> 72 if (!content::BrowserContext::GetMountPoints(profile)->
73 GetRegisteredPath(kDriveMountPointName, &ignored)) { 73 GetRegisteredPath(kDriveMountPointName, &ignored)) {
74 LOG(WARNING) << "Waiting for drive mount point to get mounted."; 74 LOG(WARNING) << "Waiting for drive mount point to get mounted.";
75 mount_point_waiter.Wait(); 75 mount_point_waiter.Wait();
76 LOG(WARNING) << "Drive mount point found."; 76 LOG(WARNING) << "Drive mount point found.";
77 } 77 }
78 } 78 }
79 79
80 } // namespace drive_test_util 80 } // namespace drive_test_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698