OLD | NEW |
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 #include "chrome/browser/chromeos/gdata/drive_task_executor.h" | 5 #include "chrome/browser/chromeos/gdata/drive_task_executor.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" | 12 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" |
13 #include "chrome/browser/chromeos/gdata/drive.pb.h" | 13 #include "chrome/browser/chromeos/gdata/drive.pb.h" |
14 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" | 14 #include "chrome/browser/chromeos/gdata/drive_service_interface.h" |
15 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 15 #include "chrome/browser/chromeos/gdata/drive_system_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_finder.h" | 19 #include "chrome/browser/ui/browser_finder.h" |
20 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "webkit/fileapi/file_system_types.h" | 23 #include "webkit/fileapi/file_system_types.h" |
24 #include "webkit/fileapi/file_system_url.h" | 24 #include "webkit/fileapi/file_system_url.h" |
25 #include "webkit/fileapi/file_system_util.h" | 25 #include "webkit/fileapi/file_system_util.h" |
(...skipping 26 matching lines...) Expand all Loading... |
52 const file_handler_util::FileTaskFinishedCallback& done) { | 52 const file_handler_util::FileTaskFinishedCallback& done) { |
53 std::vector<FilePath> raw_paths; | 53 std::vector<FilePath> raw_paths; |
54 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); | 54 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); |
55 iter != file_urls.end(); ++iter) { | 55 iter != file_urls.end(); ++iter) { |
56 fileapi::FileSystemURL url(*iter); | 56 fileapi::FileSystemURL url(*iter); |
57 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeDrive) | 57 if (!url.is_valid() || url.type() != fileapi::kFileSystemTypeDrive) |
58 return false; | 58 return false; |
59 raw_paths.push_back(url.virtual_path()); | 59 raw_paths.push_back(url.virtual_path()); |
60 } | 60 } |
61 | 61 |
62 GDataSystemService* system_service = | 62 DriveSystemService* system_service = |
63 GDataSystemServiceFactory::GetForProfile(profile()); | 63 DriveSystemServiceFactory::GetForProfile(profile()); |
64 DCHECK(current_index_ == 0); | 64 DCHECK(current_index_ == 0); |
65 if (!system_service || !system_service->file_system()) | 65 if (!system_service || !system_service->file_system()) |
66 return false; | 66 return false; |
67 DriveFileSystemInterface* file_system = system_service->file_system(); | 67 DriveFileSystemInterface* file_system = system_service->file_system(); |
68 | 68 |
69 // Reset the index, so we know when we're done. | 69 // Reset the index, so we know when we're done. |
70 current_index_ = raw_paths.size(); | 70 current_index_ = raw_paths.size(); |
71 | 71 |
72 for (std::vector<FilePath>::const_iterator iter = raw_paths.begin(); | 72 for (std::vector<FilePath>::const_iterator iter = raw_paths.begin(); |
73 iter != raw_paths.end(); ++iter) { | 73 iter != raw_paths.end(); ++iter) { |
74 file_system->GetEntryInfoByPath( | 74 file_system->GetEntryInfoByPath( |
75 *iter, | 75 *iter, |
76 base::Bind(&DriveTaskExecutor::OnFileEntryFetched, this)); | 76 base::Bind(&DriveTaskExecutor::OnFileEntryFetched, this)); |
77 } | 77 } |
78 return true; | 78 return true; |
79 } | 79 } |
80 | 80 |
81 void DriveTaskExecutor::OnFileEntryFetched( | 81 void DriveTaskExecutor::OnFileEntryFetched( |
82 DriveFileError error, | 82 DriveFileError error, |
83 scoped_ptr<DriveEntryProto> entry_proto) { | 83 scoped_ptr<DriveEntryProto> entry_proto) { |
84 // If we aborted, then this will be zero. | 84 // If we aborted, then this will be zero. |
85 if (!current_index_) | 85 if (!current_index_) |
86 return; | 86 return; |
87 | 87 |
88 GDataSystemService* system_service = | 88 DriveSystemService* system_service = |
89 GDataSystemServiceFactory::GetForProfile(profile()); | 89 DriveSystemServiceFactory::GetForProfile(profile()); |
90 | 90 |
91 // Here, we are only insterested in files. | 91 // Here, we are only insterested in files. |
92 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 92 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
93 error = DRIVE_FILE_ERROR_NOT_FOUND; | 93 error = DRIVE_FILE_ERROR_NOT_FOUND; |
94 | 94 |
95 if (!system_service || error != DRIVE_FILE_OK) { | 95 if (!system_service || error != DRIVE_FILE_OK) { |
96 Done(false); | 96 Done(false); |
97 return; | 97 return; |
98 } | 98 } |
99 | 99 |
(...skipping 14 matching lines...) Expand all Loading... |
114 void DriveTaskExecutor::OnAppAuthorized( | 114 void DriveTaskExecutor::OnAppAuthorized( |
115 const std::string& resource_id, | 115 const std::string& resource_id, |
116 GDataErrorCode error, | 116 GDataErrorCode error, |
117 scoped_ptr<base::Value> feed_data) { | 117 scoped_ptr<base::Value> feed_data) { |
118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
119 | 119 |
120 // If we aborted, then this will be zero. | 120 // If we aborted, then this will be zero. |
121 if (!current_index_) | 121 if (!current_index_) |
122 return; | 122 return; |
123 | 123 |
124 GDataSystemService* system_service = | 124 DriveSystemService* system_service = |
125 GDataSystemServiceFactory::GetForProfile(profile()); | 125 DriveSystemServiceFactory::GetForProfile(profile()); |
126 | 126 |
127 if (!system_service || error != HTTP_SUCCESS) { | 127 if (!system_service || error != HTTP_SUCCESS) { |
128 Done(false); | 128 Done(false); |
129 return; | 129 return; |
130 } | 130 } |
131 | 131 |
132 // Yay! We've got the feed data finally, and we can get the open-with URL. | 132 // Yay! We've got the feed data finally, and we can get the open-with URL. |
133 GURL open_with_url; | 133 GURL open_with_url; |
134 base::ListValue* link_list = NULL; | 134 base::ListValue* link_list = NULL; |
135 feed_data->GetAsList(&link_list); | 135 feed_data->GetAsList(&link_list); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 167 |
168 void DriveTaskExecutor::Done(bool success) { | 168 void DriveTaskExecutor::Done(bool success) { |
169 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 169 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
170 current_index_ = 0; | 170 current_index_ = 0; |
171 if (!done_.is_null()) | 171 if (!done_.is_null()) |
172 done_.Run(success); | 172 done_.Run(success); |
173 done_.Reset(); | 173 done_.Reset(); |
174 } | 174 } |
175 | 175 |
176 } // namespace gdata | 176 } // namespace gdata |
OLD | NEW |