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

Side by Side Diff: base/file_util_proxy.cc

Issue 8311010: base::Bind: Convert FileUtilProxy::CreateOrOpenCallback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 2 months 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
« no previous file with comments | « base/file_util_proxy.h ('k') | chrome/browser/nacl_host/nacl_process_host.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/file_util_proxy.h" 5 #include "base/file_util_proxy.h"
6 6
7 #include "base/message_loop_proxy.h" 7 #include "base/message_loop_proxy.h"
8 8
9 // TODO(jianli): Move the code from anonymous namespace to base namespace so 9 // TODO(jianli): Move the code from anonymous namespace to base namespace so
10 // that all of the base:: prefixes would be unnecessary. 10 // that all of the base:: prefixes would be unnecessary.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_; 113 scoped_refptr<base::MessageLoopProxy> origin_message_loop_proxy_;
114 base::PlatformFileError error_code_; 114 base::PlatformFileError error_code_;
115 }; 115 };
116 116
117 class RelayCreateOrOpen : public MessageLoopRelay { 117 class RelayCreateOrOpen : public MessageLoopRelay {
118 public: 118 public:
119 RelayCreateOrOpen( 119 RelayCreateOrOpen(
120 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 120 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
121 const FilePath& file_path, 121 const FilePath& file_path,
122 int file_flags, 122 int file_flags,
123 base::FileUtilProxy::CreateOrOpenCallback* callback) 123 const base::FileUtilProxy::CreateOrOpenCallback& callback)
124 : message_loop_proxy_(message_loop_proxy), 124 : message_loop_proxy_(message_loop_proxy),
125 file_path_(file_path), 125 file_path_(file_path),
126 file_flags_(file_flags), 126 file_flags_(file_flags),
127 callback_(callback), 127 callback_(callback),
128 file_handle_(base::kInvalidPlatformFileValue), 128 file_handle_(base::kInvalidPlatformFileValue),
129 created_(false) { 129 created_(false) {
130 DCHECK(callback); 130 DCHECK_EQ(false, callback.is_null());
131 } 131 }
132 132
133 protected: 133 protected:
134 virtual ~RelayCreateOrOpen() { 134 virtual ~RelayCreateOrOpen() {
135 if (file_handle_ != base::kInvalidPlatformFileValue) 135 if (file_handle_ != base::kInvalidPlatformFileValue)
136 base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL); 136 base::FileUtilProxy::Close(message_loop_proxy_, file_handle_, NULL);
137 } 137 }
138 138
139 virtual void RunWork() { 139 virtual void RunWork() {
140 if (!file_util::DirectoryExists(file_path_.DirName())) { 140 if (!file_util::DirectoryExists(file_path_.DirName())) {
141 // If its parent does not exist, should return NOT_FOUND error. 141 // If its parent does not exist, should return NOT_FOUND error.
142 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND); 142 set_error_code(base::PLATFORM_FILE_ERROR_NOT_FOUND);
143 return; 143 return;
144 } 144 }
145 base::PlatformFileError error_code = base::PLATFORM_FILE_OK; 145 base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
146 file_handle_ = base::CreatePlatformFile(file_path_, file_flags_, 146 file_handle_ = base::CreatePlatformFile(file_path_, file_flags_,
147 &created_, &error_code); 147 &created_, &error_code);
148 set_error_code(error_code); 148 set_error_code(error_code);
149 } 149 }
150 150
151 virtual void RunCallback() { 151 virtual void RunCallback() {
152 callback_->Run(error_code(), base::PassPlatformFile(&file_handle_), 152 callback_.Run(error_code(), base::PassPlatformFile(&file_handle_),
153 created_); 153 created_);
154 delete callback_;
155 } 154 }
156 155
157 private: 156 private:
158 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; 157 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
159 FilePath file_path_; 158 FilePath file_path_;
160 int file_flags_; 159 int file_flags_;
161 base::FileUtilProxy::CreateOrOpenCallback* callback_; 160 base::FileUtilProxy::CreateOrOpenCallback callback_;
162 base::PlatformFile file_handle_; 161 base::PlatformFile file_handle_;
163 bool created_; 162 bool created_;
164 }; 163 };
165 164
166 class RelayCreateTemporary : public MessageLoopRelay { 165 class RelayCreateTemporary : public MessageLoopRelay {
167 public: 166 public:
168 RelayCreateTemporary( 167 RelayCreateTemporary(
169 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, 168 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
170 int additional_file_flags, 169 int additional_file_flags,
171 base::FileUtilProxy::CreateTemporaryCallback* callback) 170 base::FileUtilProxy::CreateTemporaryCallback* callback)
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 } 731 }
733 732
734 } // namespace 733 } // namespace
735 734
736 namespace base { 735 namespace base {
737 736
738 // static 737 // static
739 bool FileUtilProxy::CreateOrOpen( 738 bool FileUtilProxy::CreateOrOpen(
740 scoped_refptr<MessageLoopProxy> message_loop_proxy, 739 scoped_refptr<MessageLoopProxy> message_loop_proxy,
741 const FilePath& file_path, int file_flags, 740 const FilePath& file_path, int file_flags,
742 CreateOrOpenCallback* callback) { 741 const CreateOrOpenCallback& callback) {
743 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen( 742 return Start(FROM_HERE, message_loop_proxy, new RelayCreateOrOpen(
744 message_loop_proxy, file_path, file_flags, callback)); 743 message_loop_proxy, file_path, file_flags, callback));
745 } 744 }
746 745
747 // static 746 // static
748 bool FileUtilProxy::CreateTemporary( 747 bool FileUtilProxy::CreateTemporary(
749 scoped_refptr<MessageLoopProxy> message_loop_proxy, 748 scoped_refptr<MessageLoopProxy> message_loop_proxy,
750 int additional_file_flags, 749 int additional_file_flags,
751 CreateTemporaryCallback* callback) { 750 CreateTemporaryCallback* callback) {
752 return Start(FROM_HERE, message_loop_proxy, 751 return Start(FROM_HERE, message_loop_proxy,
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 923
925 // static 924 // static
926 bool FileUtilProxy::Flush( 925 bool FileUtilProxy::Flush(
927 scoped_refptr<MessageLoopProxy> message_loop_proxy, 926 scoped_refptr<MessageLoopProxy> message_loop_proxy,
928 PlatformFile file, 927 PlatformFile file,
929 StatusCallback* callback) { 928 StatusCallback* callback) {
930 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback)); 929 return Start(FROM_HERE, message_loop_proxy, new RelayFlush(file, callback));
931 } 930 }
932 931
933 } // namespace base 932 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util_proxy.h ('k') | chrome/browser/nacl_host/nacl_process_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698