BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / sync_engine_initializer.h
blobee7df71110c07247bffdb8f6e53b425a7669ad01
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER_H_
6 #define CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER_H_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chrome/browser/sync_file_system/drive_backend/sync_task.h"
15 #include "chrome/browser/sync_file_system/sync_callbacks.h"
16 #include "google_apis/drive/drive_api_error_codes.h"
17 #include "google_apis/drive/drive_common_callbacks.h"
19 namespace drive {
20 class DriveServiceInterface;
23 namespace google_apis {
24 class AboutResource;
25 class FileList;
26 class FileResource;
29 namespace leveldb {
30 class Env;
33 namespace sync_file_system {
34 namespace drive_backend {
36 class MetadataDatabase;
37 class SyncEngineContext;
39 // This class performs initializion sequence of SyncEngine.
41 // After initialize sequence completed, the Database must have
42 // - Largest change ID,
43 // - Sync-root folder and its tracker,
44 // - All children of sync-root folder that have inactive and non-dirty
45 // trackers.
47 // The initialization sequence is:
48 // - Open database and load its contents,
49 // - If the database is already populated, complete the sequence.
50 // - Get AboutResource to get the largest change ID and the Drive root folder
51 // ID.
52 // - Find the remote sync-root folder, whose title is
53 // "Chrome Syncable FileSystem" and has no parent.
54 // Note that if the initialization is interrupted by the browser restart or
55 // an error, the sequence leaves the folder in the Drive root folder. So, if
56 // we find the folder in the Drive root folder, handle it as the sync-root
57 // folder.
58 // - Create the remote sync-root folder if we don't have.
59 // - Detach the remote sync-root folder from its parent if it has.
60 // - Fetch the folder contents of the remote sync-root folder.
61 // The contents are likely registered as app-root folders, but handle them
62 // as regular inactive folders until they are registered explicitly.
63 // - Populate database with the largest change ID, the sync-root folder and
64 // its contents.
66 class SyncEngineInitializer : public SyncTask {
67 public:
68 SyncEngineInitializer(SyncEngineContext* sync_context,
69 const base::FilePath& database_path,
70 leveldb::Env* env_override);
71 ~SyncEngineInitializer() override;
72 void RunPreflight(scoped_ptr<SyncTaskToken> token) override;
74 scoped_ptr<MetadataDatabase> PassMetadataDatabase();
76 private:
77 typedef base::Callback<void(const SyncStatusCallback& callback)> Task;
79 void GetAboutResource(scoped_ptr<SyncTaskToken> token);
80 void DidGetAboutResource(
81 scoped_ptr<SyncTaskToken> token,
82 google_apis::DriveApiErrorCode error,
83 scoped_ptr<google_apis::AboutResource> about_resource);
84 void FindSyncRoot(scoped_ptr<SyncTaskToken> token);
85 void DidFindSyncRoot(scoped_ptr<SyncTaskToken> token,
86 google_apis::DriveApiErrorCode error,
87 scoped_ptr<google_apis::FileList> file_list);
88 void CreateSyncRoot(scoped_ptr<SyncTaskToken> token);
89 void DidCreateSyncRoot(scoped_ptr<SyncTaskToken> token,
90 google_apis::DriveApiErrorCode error,
91 scoped_ptr<google_apis::FileResource> entry);
92 void DetachSyncRoot(scoped_ptr<SyncTaskToken> token);
93 void DidDetachSyncRoot(scoped_ptr<SyncTaskToken> token,
94 google_apis::DriveApiErrorCode error);
95 void ListAppRootFolders(scoped_ptr<SyncTaskToken> token);
96 void DidListAppRootFolders(
97 scoped_ptr<SyncTaskToken> token,
98 google_apis::DriveApiErrorCode error,
99 scoped_ptr<google_apis::FileList> file_list);
100 void PopulateDatabase(scoped_ptr<SyncTaskToken> token);
102 SyncEngineContext* sync_context_; // Not owned.
103 leveldb::Env* env_override_;
105 google_apis::CancelCallback cancel_callback_;
106 base::FilePath database_path_;
108 int find_sync_root_retry_count_;
110 scoped_ptr<MetadataDatabase> metadata_database_;
111 ScopedVector<google_apis::FileResource> app_root_folders_;
113 int64 largest_change_id_;
114 std::string root_folder_id_;
116 scoped_ptr<google_apis::FileResource> sync_root_folder_;
118 base::WeakPtrFactory<SyncEngineInitializer> weak_ptr_factory_;
120 DISALLOW_COPY_AND_ASSIGN(SyncEngineInitializer);
123 } // namespace drive_backend
124 } // namespace sync_file_system
126 #endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_DRIVE_BACKEND_SYNC_ENGINE_INITIALIZER_H_