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/gdata_protocol_handler.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_protocol_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
19 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 20 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
20 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 21 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
| 22 #include "chrome/browser/chromeos/gdata/gdata_operation_registry.h" |
21 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 23 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
22 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 24 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
23 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
27 #include "net/base/escape.h" | 29 #include "net/base/escape.h" |
28 #include "net/base/file_stream.h" | 30 #include "net/base/file_stream.h" |
29 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
30 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (!StartsWithASCII(path, drive_schema, false) || | 77 if (!StartsWithASCII(path, drive_schema, false) || |
76 path.size() <= drive_schema.size()) { | 78 path.size() <= drive_schema.size()) { |
77 return false; | 79 return false; |
78 } | 80 } |
79 | 81 |
80 std::string id = path.substr(drive_schema.size()); | 82 std::string id = path.substr(drive_schema.size()); |
81 *resource_id = net::UnescapeURLComponent(id, kUrlPathUnescapeMask); | 83 *resource_id = net::UnescapeURLComponent(id, kUrlPathUnescapeMask); |
82 return resource_id->size(); | 84 return resource_id->size(); |
83 } | 85 } |
84 | 86 |
85 } // namespace | 87 // Helper function to get GDataSystemService from Profile. |
| 88 GDataSystemService* GetSystemService() { |
| 89 return GDataSystemServiceFactory::GetForProfile( |
| 90 ProfileManager::GetDefaultProfile()); |
| 91 } |
86 | 92 |
87 // Helper function to get GDataFileSystem from Profile on UI thread. | 93 // Helper function to get GDataFileSystem from Profile on UI thread. |
88 void GetFileSystemOnUIThread(GDataFileSystem** file_system) { | 94 void GetFileSystemOnUIThread(GDataFileSystem** file_system) { |
89 GDataSystemService* system_service = GDataSystemServiceFactory::GetForProfile( | 95 GDataSystemService* system_service = GetSystemService(); |
90 ProfileManager::GetDefaultProfile()); | |
91 *file_system = system_service ? system_service->file_system() : NULL; | 96 *file_system = system_service ? system_service->file_system() : NULL; |
92 } | 97 } |
93 | 98 |
94 // Helper function to cancel GData download operation on UI thread. | 99 // Helper function to cancel GData download operation on UI thread. |
95 void CancelGDataDownloadOnUIThread(const FilePath& gdata_file_path) { | 100 void CancelGDataDownloadOnUIThread(const FilePath& gdata_file_path) { |
96 GDataFileSystem* file_system = NULL; | 101 GDataSystemService* system_service = GetSystemService(); |
97 GetFileSystemOnUIThread(&file_system); | 102 if (system_service) |
98 if (file_system) | 103 system_service->docs_service()->operation_registry()->CancelForFilePath( |
99 file_system->GetOperationRegistry()->CancelForFilePath(gdata_file_path); | 104 gdata_file_path); |
100 } | 105 } |
101 | 106 |
102 // GDataURLRequesetJob is the gateway between network-level drive://... | 107 // GDataURLRequesetJob is the gateway between network-level drive://... |
103 // requests for gdata resources and GDataFileSytem. It exposes content URLs | 108 // requests for gdata resources and GDataFileSytem. It exposes content URLs |
104 // formatted as drive://<resource-id>. | 109 // formatted as drive://<resource-id>. |
105 class GDataURLRequestJob : public net::URLRequestJob { | 110 class GDataURLRequestJob : public net::URLRequestJob { |
106 public: | 111 public: |
107 explicit GDataURLRequestJob(net::URLRequest* request); | 112 explicit GDataURLRequestJob(net::URLRequest* request); |
108 virtual ~GDataURLRequestJob(); | 113 virtual ~GDataURLRequestJob(); |
109 | 114 |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 | 888 |
884 response_info_.reset(new net::HttpResponseInfo()); | 889 response_info_.reset(new net::HttpResponseInfo()); |
885 response_info_->headers = headers; | 890 response_info_->headers = headers; |
886 | 891 |
887 set_expected_content_size(remaining_bytes_); | 892 set_expected_content_size(remaining_bytes_); |
888 headers_set_ = true; | 893 headers_set_ = true; |
889 | 894 |
890 NotifyHeadersComplete(); | 895 NotifyHeadersComplete(); |
891 } | 896 } |
892 | 897 |
| 898 } // namespace |
| 899 |
893 /////////////////////////////////////////////////////////////////////////////// | 900 /////////////////////////////////////////////////////////////////////////////// |
894 // GDataProtocolHandler class | 901 // GDataProtocolHandler class |
895 | 902 |
896 GDataProtocolHandler::GDataProtocolHandler() { | 903 GDataProtocolHandler::GDataProtocolHandler() { |
897 } | 904 } |
898 | 905 |
899 GDataProtocolHandler::~GDataProtocolHandler() { | 906 GDataProtocolHandler::~GDataProtocolHandler() { |
900 } | 907 } |
901 | 908 |
902 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob( | 909 net::URLRequestJob* GDataProtocolHandler::MaybeCreateJob( |
903 net::URLRequest* request) const { | 910 net::URLRequest* request) const { |
904 DVLOG(1) << "Handling url: " << request->url().spec(); | 911 DVLOG(1) << "Handling url: " << request->url().spec(); |
905 return new GDataURLRequestJob(request); | 912 return new GDataURLRequestJob(request); |
906 } | 913 } |
907 | 914 |
908 } // namespace gdata | 915 } // namespace gdata |
OLD | NEW |