Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/file_system/file_system_dispatcher_host.cc

Issue 5698008: Switch a bunch of remaining filters to derive from BrowserMessageFilters so t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/file_system/file_system_dispatcher_host.h" 5 #include "chrome/browser/file_system/file_system_dispatcher_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/thread.h" 11 #include "base/thread.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "chrome/browser/browser_thread.h"
14 #include "chrome/browser/content_settings/host_content_settings_map.h" 13 #include "chrome/browser/content_settings/host_content_settings_map.h"
15 #include "chrome/browser/file_system/browser_file_system_context.h" 14 #include "chrome/browser/file_system/browser_file_system_context.h"
16 #include "chrome/browser/net/chrome_url_request_context.h" 15 #include "chrome/browser/net/chrome_url_request_context.h"
17 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/renderer_host/browser_render_process_host.h" 17 #include "chrome/browser/renderer_host/browser_render_process_host.h"
19 #include "chrome/common/net/url_request_context_getter.h" 18 #include "chrome/common/net/url_request_context_getter.h"
20 #include "chrome/common/render_messages.h" 19 #include "chrome/common/render_messages.h"
21 #include "chrome/common/render_messages_params.h" 20 #include "chrome/common/render_messages_params.h"
22 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
23 #include "net/url_request/url_request_context.h" 22 #include "net/url_request/url_request_context.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 virtual void DidWrite(int64 bytes, bool complete) { 74 virtual void DidWrite(int64 bytes, bool complete) {
76 dispatcher_host_->Send(new ViewMsg_FileSystem_DidWrite( 75 dispatcher_host_->Send(new ViewMsg_FileSystem_DidWrite(
77 request_id_, bytes, complete)); 76 request_id_, bytes, complete));
78 } 77 }
79 78
80 private: 79 private:
81 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_; 80 scoped_refptr<FileSystemDispatcherHost> dispatcher_host_;
82 int request_id_; 81 int request_id_;
83 }; 82 };
84 83
85 FileSystemDispatcherHost::FileSystemDispatcherHost( 84 FileSystemDispatcherHost::FileSystemDispatcherHost(Profile* profile)
86 IPC::Message::Sender* sender, Profile* profile) 85 : context_(profile->GetFileSystemContext()),
87 : message_sender_(sender),
88 process_handle_(0),
89 shutdown_(false),
90 context_(profile->GetFileSystemContext()),
91 host_content_settings_map_(profile->GetHostContentSettingsMap()), 86 host_content_settings_map_(profile->GetHostContentSettingsMap()),
92 request_context_getter_(profile->GetRequestContext()) { 87 request_context_getter_(profile->GetRequestContext()) {
93 DCHECK(message_sender_);
94 } 88 }
95 89
96 FileSystemDispatcherHost::FileSystemDispatcherHost( 90 FileSystemDispatcherHost::FileSystemDispatcherHost(
97 IPC::Message::Sender* sender, ChromeURLRequestContext* context) 91 ChromeURLRequestContext* context)
98 : message_sender_(sender), 92 : context_(context->browser_file_system_context()),
99 process_handle_(0),
100 shutdown_(false),
101 context_(context->browser_file_system_context()),
102 host_content_settings_map_(context->host_content_settings_map()), 93 host_content_settings_map_(context->host_content_settings_map()),
103 request_context_(context) { 94 request_context_(context) {
104 DCHECK(message_sender_);
105 } 95 }
106 96
107 FileSystemDispatcherHost::~FileSystemDispatcherHost() { 97 FileSystemDispatcherHost::~FileSystemDispatcherHost() {
108 } 98 }
109 99
110 void FileSystemDispatcherHost::Init(base::ProcessHandle process_handle) { 100 void FileSystemDispatcherHost::OnChannelConnected(int32 peer_pid) {
111 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 101 BrowserMessageFilter::OnChannelConnected(peer_pid);
112 DCHECK(!shutdown_); 102
113 DCHECK(!process_handle_);
114 DCHECK(process_handle);
115 process_handle_ = process_handle;
116 if (request_context_getter_.get()) { 103 if (request_context_getter_.get()) {
117 DCHECK(!request_context_.get()); 104 DCHECK(!request_context_.get());
118 request_context_ = request_context_getter_->GetURLRequestContext(); 105 request_context_ = request_context_getter_->GetURLRequestContext();
119 } 106 }
120 DCHECK(request_context_.get()); 107 DCHECK(request_context_.get());
121 } 108 }
122 109
123 void FileSystemDispatcherHost::Shutdown() {
124 message_sender_ = NULL;
125 shutdown_ = true;
126 }
127
128 bool FileSystemDispatcherHost::OnMessageReceived( 110 bool FileSystemDispatcherHost::OnMessageReceived(
129 const IPC::Message& message, bool* message_was_ok) { 111 const IPC::Message& message, bool* message_was_ok) {
130 DCHECK(!shutdown_);
131 *message_was_ok = true; 112 *message_was_ok = true;
132 bool handled = true; 113 bool handled = true;
133 IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok) 114 IPC_BEGIN_MESSAGE_MAP_EX(FileSystemDispatcherHost, message, *message_was_ok)
134 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem) 115 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenFileSystemRequest, OnOpenFileSystem)
135 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove) 116 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Move, OnMove)
136 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Copy, OnCopy) 117 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Copy, OnCopy)
137 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Remove, OnRemove) 118 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Remove, OnRemove)
138 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadMetadata, OnReadMetadata) 119 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_ReadMetadata, OnReadMetadata)
139 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate) 120 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Create, OnCreate)
140 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists) 121 IPC_MESSAGE_HANDLER(ViewHostMsg_FileSystem_Exists, OnExists)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // The cancel will eventually send both the write failure and the cancel 225 // The cancel will eventually send both the write failure and the cancel
245 // success. 226 // success.
246 write->Cancel(GetNewOperation(request_id)); 227 write->Cancel(GetNewOperation(request_id));
247 } else { 228 } else {
248 // The write already finished; report that we failed to stop it. 229 // The write already finished; report that we failed to stop it.
249 Send(new ViewMsg_FileSystem_DidFail( 230 Send(new ViewMsg_FileSystem_DidFail(
250 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION)); 231 request_id, base::PLATFORM_FILE_ERROR_INVALID_OPERATION));
251 } 232 }
252 } 233 }
253 234
254 void FileSystemDispatcherHost::Send(IPC::Message* message) {
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
256 if (!shutdown_ && message_sender_)
257 message_sender_->Send(message);
258 else
259 delete message;
260 }
261
262 SandboxedFileSystemOperation* FileSystemDispatcherHost::GetNewOperation( 235 SandboxedFileSystemOperation* FileSystemDispatcherHost::GetNewOperation(
263 int request_id) { 236 int request_id) {
264 BrowserFileSystemCallbackDispatcher* dispatcher = 237 BrowserFileSystemCallbackDispatcher* dispatcher =
265 new BrowserFileSystemCallbackDispatcher(this, request_id); 238 new BrowserFileSystemCallbackDispatcher(this, request_id);
266 SandboxedFileSystemOperation* operation = new SandboxedFileSystemOperation( 239 SandboxedFileSystemOperation* operation = new SandboxedFileSystemOperation(
267 dispatcher, 240 dispatcher,
268 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), 241 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
269 context_.get()); 242 context_.get());
270 operations_.AddWithID(operation, request_id); 243 operations_.AddWithID(operation, request_id);
271 return operation; 244 return operation;
272 } 245 }
273 246
274 void FileSystemDispatcherHost::UnregisterOperation(int request_id) { 247 void FileSystemDispatcherHost::UnregisterOperation(int request_id) {
275 DCHECK(operations_.Lookup(request_id)); 248 DCHECK(operations_.Lookup(request_id));
276 operations_.Remove(request_id); 249 operations_.Remove(request_id);
277 } 250 }
OLDNEW
« no previous file with comments | « chrome/browser/file_system/file_system_dispatcher_host.h ('k') | chrome/browser/mime_registry_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698