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

Unified Diff: mojo/services/network/network_service_delegate.cc

Issue 1179413010: mandoline filesystem: Save cookie data to the mojo:filesystem. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sqlite-fs
Patch Set: Maybe this time. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: mojo/services/network/network_service_delegate.cc
diff --git a/mojo/services/network/network_service_delegate.cc b/mojo/services/network/network_service_delegate.cc
index b3b1c8e8a4bf546bfa4e8ccdc22ddcebc2330811..ef3a129cdd2a718cd230306286f8701cb2c3fb80 100644
--- a/mojo/services/network/network_service_delegate.cc
+++ b/mojo/services/network/network_service_delegate.cc
@@ -6,23 +6,87 @@
#include "base/at_exit.h"
#include "base/base_paths.h"
+#include "base/bind.h"
#include "base/files/file_path.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "mojo/application/public/cpp/application_connection.h"
+#include "mojo/common/message_pump_mojo.h"
#include "mojo/services/network/network_service_impl.h"
#include "mojo/services/network/url_loader_factory_impl.h"
+#include "mojo/util/capture_util.h"
+#include "sql/mojo/mojo_vfs.h"
-NetworkServiceDelegate::NetworkServiceDelegate() : app_(nullptr) {}
+namespace {
-NetworkServiceDelegate::~NetworkServiceDelegate() {}
+const char kSQLThreadName[] = "SQL_IO_Thread";
+
+// SQL blocks on the filesystem service, so perform all SQL functions on a
+// separate thread.
+class SQLThread : public base::Thread {
+ public:
+ SQLThread(filesystem::DirectoryPtr directory)
+ : base::Thread(kSQLThreadName),
+ directory_info_(directory.PassInterface().Pass()) {
+ base::Thread::Options options;
+ options.message_pump_factory =
+ base::Bind(&mojo::common::MessagePumpMojo::Create);
+ StartWithOptions(options);
+ }
+ ~SQLThread() override { Stop(); }
+
+ void Init() override {
+ filesystem::DirectoryPtr directory;
+ directory.Bind(directory_info_.Pass());
+ vfs_.reset(new sql::ScopedMojoFilesystemVFS(directory.Pass()));
+ }
+
+ void CleanUp() override {
+ vfs_.reset();
+ }
+
+ private:
+ // Our VFS which wraps sqlite so that we can reuse the current sqlite code.
+ scoped_ptr<sql::ScopedMojoFilesystemVFS> vfs_;
+
+ // This member is used to safely pass data from one thread to another. It is
+ // set in the constructor and is consumed in Init().
+ mojo::InterfacePtrInfo<filesystem::Directory> directory_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(SQLThread);
+};
+
+} // namespace
+
+NetworkServiceDelegate::NetworkServiceDelegate()
+ : app_(nullptr) {
+}
+
+NetworkServiceDelegate::~NetworkServiceDelegate() {
+}
void NetworkServiceDelegate::Initialize(mojo::ApplicationImpl* app) {
app_ = app;
+
+ mojo::URLRequestPtr request(mojo::URLRequest::New());
+ request->url = mojo::String::From("mojo:filesystem");
+ app_->ConnectToService(request.Pass(), &files_);
+
+ filesystem::FileError error = filesystem::FILE_ERROR_FAILED;
+ filesystem::DirectoryPtr directory;
+ files_->OpenFileSystem("origin", GetProxy(&directory), mojo::Capture(&error));
+ files_.WaitForIncomingResponse();
+
+ io_worker_thread_.reset(new SQLThread(directory.Pass()));
+
+ // TODO(erg): Find everything else that writes to the filesystem and
+ // transition it to proxying mojo:filesystem
base::FilePath base_path;
CHECK(PathService::Get(base::DIR_TEMP, &base_path));
base_path = base_path.Append(FILE_PATH_LITERAL("network_service"));
- context_.reset(new mojo::NetworkContext(base_path));
+
+ context_.reset(new mojo::NetworkContext(
+ base_path, io_worker_thread_->task_runner()));
}
bool NetworkServiceDelegate::ConfigureIncomingConnection(
@@ -38,6 +102,10 @@ void NetworkServiceDelegate::Quit() {
// destruction and it is the last moment we know for sure that it is
// running.
context_.reset();
+
+ // Destroy the io worker thread here so that we can commit any pending
+ // cookies here.
+ io_worker_thread_.reset();
Elliot Glaysher 2015/06/22 20:03:31 I worry about timing and unclean pipe shutdown. I
}
void NetworkServiceDelegate::Create(

Powered by Google App Engine
This is Rietveld 408576698