OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_usage_tracker.h" | 5 #include "webkit/fileapi/file_system_usage_tracker.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/task.h" | 14 #include "base/task.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 #include "webkit/fileapi/file_system_path_manager.h" | 16 #include "webkit/fileapi/file_system_path_manager.h" |
17 #include "webkit/fileapi/file_system_usage_cache.h" | 17 #include "webkit/fileapi/file_system_usage_cache.h" |
| 18 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
18 | 19 |
19 namespace fileapi { | 20 namespace fileapi { |
20 | 21 |
21 class FileSystemUsageTracker::GetUsageTask | 22 class FileSystemUsageTracker::GetUsageTask |
22 : public base::RefCountedThreadSafe<GetUsageTask> { | 23 : public base::RefCountedThreadSafe<GetUsageTask> { |
23 public: | 24 public: |
24 GetUsageTask( | 25 GetUsageTask( |
25 FileSystemUsageTracker* tracker, | 26 FileSystemUsageTracker* tracker, |
26 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 27 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
27 std::string fs_identifier, | 28 std::string fs_identifier, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 int64 fs_usage_; | 92 int64 fs_usage_; |
92 FilePath origin_base_path_; | 93 FilePath origin_base_path_; |
93 }; | 94 }; |
94 | 95 |
95 FileSystemUsageTracker::FileSystemUsageTracker( | 96 FileSystemUsageTracker::FileSystemUsageTracker( |
96 scoped_refptr<base::MessageLoopProxy> file_message_loop, | 97 scoped_refptr<base::MessageLoopProxy> file_message_loop, |
97 const FilePath& profile_path, | 98 const FilePath& profile_path, |
98 bool is_incognito) | 99 bool is_incognito) |
99 : file_message_loop_(file_message_loop), | 100 : file_message_loop_(file_message_loop), |
100 base_path_(profile_path.Append( | 101 base_path_(profile_path.Append( |
101 FileSystemPathManager::kFileSystemDirectory)), | 102 SandboxMountPointProvider::kFileSystemDirectory)), |
102 is_incognito_(is_incognito) { | 103 is_incognito_(is_incognito) { |
103 DCHECK(file_message_loop); | 104 DCHECK(file_message_loop); |
104 } | 105 } |
105 | 106 |
106 FileSystemUsageTracker::~FileSystemUsageTracker() { | 107 FileSystemUsageTracker::~FileSystemUsageTracker() { |
107 std::for_each(running_usage_tasks_.begin(), | 108 std::for_each(running_usage_tasks_.begin(), |
108 running_usage_tasks_.end(), | 109 running_usage_tasks_.end(), |
109 std::mem_fun(&GetUsageTask::Cancel)); | 110 std::mem_fun(&GetUsageTask::Cancel)); |
110 } | 111 } |
111 | 112 |
112 void FileSystemUsageTracker::GetOriginUsage( | 113 void FileSystemUsageTracker::GetOriginUsage( |
113 const GURL& origin_url, | 114 const GURL& origin_url, |
114 fileapi::FileSystemType type, | 115 fileapi::FileSystemType type, |
115 GetUsageCallback* callback_ptr) { | 116 GetUsageCallback* callback_ptr) { |
116 DCHECK(callback_ptr); | 117 DCHECK(callback_ptr); |
117 scoped_ptr<GetUsageCallback> callback(callback_ptr); | 118 scoped_ptr<GetUsageCallback> callback(callback_ptr); |
118 | 119 |
119 if (is_incognito_) { | 120 if (is_incognito_) { |
120 // We don't support FileSystem in incognito mode yet. | 121 // We don't support FileSystem in incognito mode yet. |
121 callback->Run(0); | 122 callback->Run(0); |
122 return; | 123 return; |
123 } | 124 } |
124 | 125 |
125 std::string origin_identifier = | 126 std::string origin_identifier = |
126 FileSystemPathManager::GetOriginIdentifierFromURL(origin_url); | 127 SandboxMountPointProvider::GetOriginIdentifierFromURL(origin_url); |
127 std::string type_string = | 128 std::string type_string = |
128 FileSystemPathManager::GetFileSystemTypeString(type); | 129 FileSystemPathManager::GetFileSystemTypeString(type); |
129 std::string fs_identifier = origin_identifier + ":" + type_string; | 130 std::string fs_identifier = origin_identifier + ":" + type_string; |
130 | 131 |
131 if (pending_usage_callbacks_.find(fs_identifier) != | 132 if (pending_usage_callbacks_.find(fs_identifier) != |
132 pending_usage_callbacks_.end()) { | 133 pending_usage_callbacks_.end()) { |
133 // Another get usage task is running. Add the callback to | 134 // Another get usage task is running. Add the callback to |
134 // the pending queue and return. | 135 // the pending queue and return. |
135 pending_usage_callbacks_[fs_identifier].push_back(callback.release()); | 136 pending_usage_callbacks_[fs_identifier].push_back(callback.release()); |
136 return; | 137 return; |
137 } | 138 } |
138 | 139 |
139 // Get the filesystem base path (i.e. "FileSystem/<origin>/<type>", | 140 // Get the filesystem base path (i.e. "FileSystem/<origin>/<type>", |
140 // without unique part). | 141 // without unique part). |
141 FilePath origin_base_path = | 142 FilePath origin_base_path = |
142 FileSystemPathManager::GetFileSystemBaseDirectoryForOriginAndType( | 143 SandboxMountPointProvider::GetFileSystemBaseDirectoryForOriginAndType( |
143 base_path_, origin_identifier, type); | 144 base_path_, origin_identifier, type); |
144 if (origin_base_path.empty()) { | 145 if (origin_base_path.empty()) { |
145 // The directory does not exist. | 146 // The directory does not exist. |
146 callback->Run(0); | 147 callback->Run(0); |
147 return; | 148 return; |
148 } | 149 } |
149 | 150 |
150 pending_usage_callbacks_[fs_identifier].push_back(callback.release()); | 151 pending_usage_callbacks_[fs_identifier].push_back(callback.release()); |
151 scoped_refptr<GetUsageTask> task( | 152 scoped_refptr<GetUsageTask> task( |
152 new GetUsageTask(this, file_message_loop_, fs_identifier, | 153 new GetUsageTask(this, file_message_loop_, fs_identifier, |
(...skipping 19 matching lines...) Expand all Loading... |
172 for (PendingCallbackList::iterator cb_iter = cb_list.begin(); | 173 for (PendingCallbackList::iterator cb_iter = cb_list.begin(); |
173 cb_iter != cb_list.end(); | 174 cb_iter != cb_list.end(); |
174 ++cb_iter) { | 175 ++cb_iter) { |
175 scoped_ptr<GetUsageCallback> callback(*cb_iter); | 176 scoped_ptr<GetUsageCallback> callback(*cb_iter); |
176 callback->Run(usage); | 177 callback->Run(usage); |
177 } | 178 } |
178 pending_usage_callbacks_.erase(cb_list_iter); | 179 pending_usage_callbacks_.erase(cb_list_iter); |
179 } | 180 } |
180 | 181 |
181 } // namespace fileapi | 182 } // namespace fileapi |
OLD | NEW |