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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 iter != file_urls.end(); ++iter) { | 54 iter != file_urls.end(); ++iter) { |
55 FilePath raw_path; | 55 FilePath raw_path; |
56 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; | 56 fileapi::FileSystemType type = fileapi::kFileSystemTypeUnknown; |
57 if (!fileapi::CrackFileSystemURL(*iter, NULL, &type, &raw_path) || | 57 if (!fileapi::CrackFileSystemURL(*iter, NULL, &type, &raw_path) || |
58 type != fileapi::kFileSystemTypeExternal) { | 58 type != fileapi::kFileSystemTypeExternal) { |
59 return false; | 59 return false; |
60 } | 60 } |
61 raw_paths.push_back(raw_path); | 61 raw_paths.push_back(raw_path); |
62 } | 62 } |
63 | 63 |
64 gdata::GDataSystemService* system_service = | 64 GDataSystemService* system_service = |
65 gdata::GDataSystemServiceFactory::GetForProfile(profile()); | 65 GDataSystemServiceFactory::GetForProfile(profile()); |
66 DCHECK(current_index_ == 0); | 66 DCHECK(current_index_ == 0); |
67 if (!system_service || !system_service->file_system()) | 67 if (!system_service || !system_service->file_system()) |
68 return false; | 68 return false; |
69 gdata::GDataFileSystemInterface* file_system = system_service->file_system(); | 69 GDataFileSystemInterface* file_system = system_service->file_system(); |
70 | 70 |
71 // Reset the index, so we know when we're done. | 71 // Reset the index, so we know when we're done. |
72 current_index_ = raw_paths.size(); | 72 current_index_ = raw_paths.size(); |
73 | 73 |
74 for (std::vector<FilePath>::const_iterator iter = raw_paths.begin(); | 74 for (std::vector<FilePath>::const_iterator iter = raw_paths.begin(); |
75 iter != raw_paths.end(); ++iter) { | 75 iter != raw_paths.end(); ++iter) { |
76 file_system->GetEntryInfoByPath( | 76 file_system->GetEntryInfoByPath( |
77 *iter, | 77 *iter, |
78 base::Bind(&DriveTaskExecutor::OnFileEntryFetched, this)); | 78 base::Bind(&DriveTaskExecutor::OnFileEntryFetched, this)); |
79 } | 79 } |
80 return true; | 80 return true; |
81 } | 81 } |
82 | 82 |
83 void DriveTaskExecutor::OnFileEntryFetched( | 83 void DriveTaskExecutor::OnFileEntryFetched( |
84 GDataFileError error, | 84 GDataFileError error, |
85 scoped_ptr<gdata::GDataEntryProto> entry_proto) { | 85 scoped_ptr<GDataEntryProto> entry_proto) { |
86 // If we aborted, then this will be zero. | 86 // If we aborted, then this will be zero. |
87 if (!current_index_) | 87 if (!current_index_) |
88 return; | 88 return; |
89 | 89 |
90 gdata::GDataSystemService* system_service = | 90 GDataSystemService* system_service = |
91 gdata::GDataSystemServiceFactory::GetForProfile(profile()); | 91 GDataSystemServiceFactory::GetForProfile(profile()); |
92 | 92 |
93 // Here, we are only insterested in files. | 93 // Here, we are only insterested in files. |
94 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 94 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
95 error = gdata::GDATA_FILE_ERROR_NOT_FOUND; | 95 error = GDATA_FILE_ERROR_NOT_FOUND; |
96 | 96 |
97 if (!system_service || error != GDATA_FILE_OK) { | 97 if (!system_service || error != GDATA_FILE_OK) { |
98 Done(false); | 98 Done(false); |
99 return; | 99 return; |
100 } | 100 } |
101 | 101 |
102 gdata::DocumentsServiceInterface* docs_service = | 102 DocumentsServiceInterface* docs_service = |
103 system_service->docs_service(); | 103 system_service->docs_service(); |
104 | 104 |
105 // Send off a request for the document service to authorize the apps for the | 105 // Send off a request for the document service to authorize the apps for the |
106 // current document entry for this document so we can get the | 106 // current document entry for this document so we can get the |
107 // open-with-<app_id> urls from the document entry. | 107 // open-with-<app_id> urls from the document entry. |
108 docs_service->AuthorizeApp( | 108 docs_service->AuthorizeApp( |
109 GURL(entry_proto->edit_url()), | 109 GURL(entry_proto->edit_url()), |
110 app_id_, | 110 app_id_, |
111 base::Bind(&DriveTaskExecutor::OnAppAuthorized, | 111 base::Bind(&DriveTaskExecutor::OnAppAuthorized, |
112 this, | 112 this, |
113 entry_proto->resource_id())); | 113 entry_proto->resource_id())); |
114 } | 114 } |
115 | 115 |
116 void DriveTaskExecutor::OnAppAuthorized( | 116 void DriveTaskExecutor::OnAppAuthorized( |
117 const std::string& resource_id, | 117 const std::string& resource_id, |
118 gdata::GDataErrorCode error, | 118 GDataErrorCode error, |
119 scoped_ptr<base::Value> feed_data) { | 119 scoped_ptr<base::Value> feed_data) { |
120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
121 | 121 |
122 // If we aborted, then this will be zero. | 122 // If we aborted, then this will be zero. |
123 if (!current_index_) | 123 if (!current_index_) |
124 return; | 124 return; |
125 | 125 |
126 gdata::GDataSystemService* system_service = | 126 GDataSystemService* system_service = |
127 gdata::GDataSystemServiceFactory::GetForProfile(profile()); | 127 GDataSystemServiceFactory::GetForProfile(profile()); |
128 | 128 |
129 if (!system_service || error != gdata::HTTP_SUCCESS) { | 129 if (!system_service || error != HTTP_SUCCESS) { |
130 Done(false); | 130 Done(false); |
131 return; | 131 return; |
132 } | 132 } |
133 | 133 |
134 // Yay! We've got the feed data finally, and we can get the open-with URL. | 134 // Yay! We've got the feed data finally, and we can get the open-with URL. |
135 GURL open_with_url; | 135 GURL open_with_url; |
136 base::ListValue* link_list = NULL; | 136 base::ListValue* link_list = NULL; |
137 feed_data->GetAsList(&link_list); | 137 feed_data->GetAsList(&link_list); |
138 for (size_t i = 0; i < link_list->GetSize(); ++i) { | 138 for (size_t i = 0; i < link_list->GetSize(); ++i) { |
139 DictionaryValue* entry = NULL; | 139 DictionaryValue* entry = NULL; |
(...skipping 29 matching lines...) Expand all Loading... |
169 | 169 |
170 void DriveTaskExecutor::Done(bool success) { | 170 void DriveTaskExecutor::Done(bool success) { |
171 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 171 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
172 current_index_ = 0; | 172 current_index_ = 0; |
173 if (!done_.is_null()) | 173 if (!done_.is_null()) |
174 done_.Run(success); | 174 done_.Run(success); |
175 done_.Reset(); | 175 done_.Reset(); |
176 } | 176 } |
177 | 177 |
178 } // namespace gdata | 178 } // namespace gdata |
OLD | NEW |