| 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 13 matching lines...) Expand all Loading... |
| 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" |
| 26 | 26 |
| 27 namespace gdata { | 27 namespace gdata { |
| 28 | 28 |
| 29 using file_handler_util::FileTaskExecutor; | 29 using file_handler_util::FileTaskExecutor; |
| 30 | 30 |
| 31 DriveTaskExecutor::DriveTaskExecutor(Profile* profile, | 31 DriveTaskExecutor::DriveTaskExecutor(Profile* profile, |
| 32 const std::string& app_id, | 32 const std::string& app_id, |
| 33 const std::string& action_id) | 33 const std::string& action_id) |
| 34 : file_handler_util::FileTaskExecutor(profile), | 34 : file_handler_util::FileTaskExecutor(profile, app_id), |
| 35 app_id_(app_id), | |
| 36 action_id_(action_id), | 35 action_id_(action_id), |
| 37 current_index_(0) { | 36 current_index_(0) { |
| 38 DCHECK("open-with" == action_id_); | 37 DCHECK("open-with" == action_id_); |
| 39 DCHECK(app_id.size() > FileTaskExecutor::kDriveTaskExtensionPrefixLength); | |
| 40 DCHECK(StartsWithASCII(app_id, | |
| 41 FileTaskExecutor::kDriveTaskExtensionPrefix, | |
| 42 false)); | |
| 43 // Strip off the prefix from the extension ID so we convert it to an app id. | |
| 44 app_id_ = app_id_.substr(FileTaskExecutor::kDriveTaskExtensionPrefixLength); | |
| 45 } | 38 } |
| 46 | 39 |
| 47 DriveTaskExecutor::~DriveTaskExecutor() { | 40 DriveTaskExecutor::~DriveTaskExecutor() { |
| 48 } | 41 } |
| 49 | 42 |
| 50 bool DriveTaskExecutor::ExecuteAndNotify( | 43 bool DriveTaskExecutor::ExecuteAndNotify( |
| 51 const std::vector<GURL>& file_urls, | 44 const std::vector<GURL>& file_urls, |
| 52 const file_handler_util::FileTaskFinishedCallback& done) { | 45 const file_handler_util::FileTaskFinishedCallback& done) { |
| 53 std::vector<FilePath> raw_paths; | 46 std::vector<FilePath> raw_paths; |
| 54 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); | 47 for (std::vector<GURL>::const_iterator iter = file_urls.begin(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 91 } |
| 99 | 92 |
| 100 DriveServiceInterface* drive_service = | 93 DriveServiceInterface* drive_service = |
| 101 system_service->drive_service(); | 94 system_service->drive_service(); |
| 102 | 95 |
| 103 // Send off a request for the drive service to authorize the apps for the | 96 // Send off a request for the drive service to authorize the apps for the |
| 104 // current document entry for this document so we can get the | 97 // current document entry for this document so we can get the |
| 105 // open-with-<app_id> urls from the document entry. | 98 // open-with-<app_id> urls from the document entry. |
| 106 drive_service->AuthorizeApp( | 99 drive_service->AuthorizeApp( |
| 107 GURL(entry_proto->edit_url()), | 100 GURL(entry_proto->edit_url()), |
| 108 app_id_, | 101 extension_id(), // really app_id |
| 109 base::Bind(&DriveTaskExecutor::OnAppAuthorized, | 102 base::Bind(&DriveTaskExecutor::OnAppAuthorized, |
| 110 this, | 103 this, |
| 111 entry_proto->resource_id())); | 104 entry_proto->resource_id())); |
| 112 } | 105 } |
| 113 | 106 |
| 114 void DriveTaskExecutor::OnAppAuthorized( | 107 void DriveTaskExecutor::OnAppAuthorized( |
| 115 const std::string& resource_id, | 108 const std::string& resource_id, |
| 116 GDataErrorCode error, | 109 GDataErrorCode error, |
| 117 scoped_ptr<base::Value> feed_data) { | 110 scoped_ptr<base::Value> feed_data) { |
| 118 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 111 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 131 | 124 |
| 132 // Yay! We've got the feed data finally, and we can get the open-with URL. | 125 // Yay! We've got the feed data finally, and we can get the open-with URL. |
| 133 GURL open_with_url; | 126 GURL open_with_url; |
| 134 base::ListValue* link_list = NULL; | 127 base::ListValue* link_list = NULL; |
| 135 feed_data->GetAsList(&link_list); | 128 feed_data->GetAsList(&link_list); |
| 136 for (size_t i = 0; i < link_list->GetSize(); ++i) { | 129 for (size_t i = 0; i < link_list->GetSize(); ++i) { |
| 137 DictionaryValue* entry = NULL; | 130 DictionaryValue* entry = NULL; |
| 138 link_list->GetDictionary(i, &entry); | 131 link_list->GetDictionary(i, &entry); |
| 139 std::string app_id; | 132 std::string app_id; |
| 140 entry->GetString("app_id", &app_id); | 133 entry->GetString("app_id", &app_id); |
| 141 if (app_id == app_id_) { | 134 if (app_id == extension_id()) { |
| 142 std::string href; | 135 std::string href; |
| 143 entry->GetString("href", &href); | 136 entry->GetString("href", &href); |
| 144 open_with_url = GURL(href); | 137 open_with_url = GURL(href); |
| 145 break; | 138 break; |
| 146 } | 139 } |
| 147 } | 140 } |
| 148 | 141 |
| 149 if (open_with_url.is_empty()) { | 142 if (open_with_url.is_empty()) { |
| 150 Done(false); | 143 Done(false); |
| 151 return; | 144 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 167 | 160 |
| 168 void DriveTaskExecutor::Done(bool success) { | 161 void DriveTaskExecutor::Done(bool success) { |
| 169 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 162 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 170 current_index_ = 0; | 163 current_index_ = 0; |
| 171 if (!done_.is_null()) | 164 if (!done_.is_null()) |
| 172 done_.Run(success); | 165 done_.Run(success); |
| 173 done_.Reset(); | 166 done_.Reset(); |
| 174 } | 167 } |
| 175 | 168 |
| 176 } // namespace gdata | 169 } // namespace gdata |
| OLD | NEW |