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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_download_observer.h

Issue 10759007: gdata: Move GDataFileSystem::AddUploadedFile() call out of uploader and into GDataDownloadObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ 5 #ifndef CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__
6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ 6 #define CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/platform_file.h" 13 #include "base/platform_file.h"
14 #include "content/public/browser/download_item.h" 14 #include "content/public/browser/download_item.h"
15 #include "content/public/browser/download_manager.h" 15 #include "content/public/browser/download_manager.h"
16 16
17 class Profile; 17 class Profile;
18 18
19 namespace gdata { 19 namespace gdata {
20 20
21 class DocumentEntry; 21 class DocumentEntry;
22 class GDataFileSystem;
22 class GDataUploader; 23 class GDataUploader;
23 struct UploadFileInfo; 24 struct UploadFileInfo;
24 25
25 // Observes downloads to temporary local gdata folder. Schedules these 26 // Observes downloads to temporary local gdata folder. Schedules these
26 // downloads for upload to gdata service. 27 // downloads for upload to gdata service.
27 class GDataDownloadObserver : public content::DownloadManager::Observer, 28 class GDataDownloadObserver : public content::DownloadManager::Observer,
28 public content::DownloadItem::Observer { 29 public content::DownloadItem::Observer {
29 public: 30 public:
30 GDataDownloadObserver(); 31 GDataDownloadObserver(GDataUploader* uploader, GDataFileSystem* file_system);
31 virtual ~GDataDownloadObserver(); 32 virtual ~GDataDownloadObserver();
32 33
33 // Become an observer of DownloadManager. 34 // Become an observer of DownloadManager.
34 void Initialize(GDataUploader* gdata_uploader, 35 void Initialize(content::DownloadManager* download_manager,
35 content::DownloadManager* download_manager,
36 const FilePath& gdata_tmp_download_path); 36 const FilePath& gdata_tmp_download_path);
37 37
38 typedef base::Callback<void(const FilePath&)> 38 typedef base::Callback<void(const FilePath&)>
39 SubstituteGDataDownloadPathCallback; 39 SubstituteGDataDownloadPathCallback;
40 static void SubstituteGDataDownloadPath(Profile* profile, 40 static void SubstituteGDataDownloadPath(Profile* profile,
41 const FilePath& gdata_path, content::DownloadItem* download, 41 const FilePath& gdata_path, content::DownloadItem* download,
42 const SubstituteGDataDownloadPathCallback& callback); 42 const SubstituteGDataDownloadPathCallback& callback);
43 43
44 // Sets gdata path, for example, '/special/drive/MyFolder/MyFile', 44 // Sets gdata path, for example, '/special/drive/MyFolder/MyFile',
45 // to external data in |download|. Also sets display name and 45 // to external data in |download|. Also sets display name and
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 // Checks if this DownloadItem should be uploaded. 108 // Checks if this DownloadItem should be uploaded.
109 bool ShouldUpload(content::DownloadItem* download); 109 bool ShouldUpload(content::DownloadItem* download);
110 110
111 // Creates UploadFileInfo and initializes it using DownloadItem*. 111 // Creates UploadFileInfo and initializes it using DownloadItem*.
112 scoped_ptr<UploadFileInfo> CreateUploadFileInfo( 112 scoped_ptr<UploadFileInfo> CreateUploadFileInfo(
113 content::DownloadItem* download); 113 content::DownloadItem* download);
114 114
115 // Callback invoked by GDataUploader when the upload associated with 115 // Callback invoked by GDataUploader when the upload associated with
116 // |download_id| has completed. |error| indicated whether the 116 // |download_id| has completed. |error| indicated whether the
117 // call was successful. This function invokes the MaybeCompleteDownload() 117 // call was successful. This function performs the following tasks:
118 // method on the DownloadItem to allow it to complete. 118 // - Invoke the AddUploadedFile() method on the file system to move the file
119 // to gdata cache;
120 // - Invoke the MaybeCompleteDownload() method on the DownloadItem to allow it
121 // to complete.
119 void OnUploadComplete(int32 download_id, 122 void OnUploadComplete(int32 download_id,
120 base::PlatformFileError error, 123 base::PlatformFileError error,
121 scoped_ptr<UploadFileInfo> upload_file_info); 124 scoped_ptr<UploadFileInfo> upload_file_info);
122 125
123 // Private data. 126 // Private data.
124 // Use GDataUploader to trigger file uploads. 127 // The uploader owned by GDataSystemService. Used to trigger file uploads.
125 GDataUploader* gdata_uploader_; 128 GDataUploader* gdata_uploader_;
129 // The file system owned by GDataSystemService.
130 GDataFileSystem* file_system_;
126 // Observe the DownloadManager for new downloads. 131 // Observe the DownloadManager for new downloads.
127 content::DownloadManager* download_manager_; 132 content::DownloadManager* download_manager_;
128 133
129 // Temporary download location directory. 134 // Temporary download location directory.
130 FilePath gdata_tmp_download_path_; 135 FilePath gdata_tmp_download_path_;
131 136
132 // Map of pending downloads. 137 // Map of pending downloads.
133 typedef std::map<int32, content::DownloadItem*> DownloadMap; 138 typedef std::map<int32, content::DownloadItem*> DownloadMap;
134 DownloadMap pending_downloads_; 139 DownloadMap pending_downloads_;
135 140
136 base::WeakPtrFactory<GDataDownloadObserver> weak_ptr_factory_; 141 base::WeakPtrFactory<GDataDownloadObserver> weak_ptr_factory_;
137 142
138 DISALLOW_COPY_AND_ASSIGN(GDataDownloadObserver); 143 DISALLOW_COPY_AND_ASSIGN(GDataDownloadObserver);
139 }; 144 };
140 145
141 } // namespace gdata 146 } // namespace gdata
142 147
143 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__ 148 #endif // CHROME_BROWSER_CHROMEOS_GDATA_GDATA_DOWNLOAD_OBSERVER_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698