Chromium Code Reviews| Index: apps/app_shim/app_shim_host_controller.mm |
| diff --git a/apps/app_shim/app_shim_host_controller.mm b/apps/app_shim/app_shim_host_controller.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4de0015cc41a0d4d80e99d59ce71e2ae12eca42d |
| --- /dev/null |
| +++ b/apps/app_shim/app_shim_host_controller.mm |
| @@ -0,0 +1,71 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "apps/app_shim/app_shim_host_controller.h" |
| + |
| +#include "apps/app_shim/app_shim_host.h" |
| +#include "base/bind.h" |
| +#include "base/files/file_path.h" |
| +#include "base/logging.h" |
| +#include "base/path_service.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "chrome/common/mac/app_mode_common.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace { |
| + |
| +void CreateAppShimHost(const IPC::ChannelHandle& handle) { |
| + AppShimHost* host = new AppShimHost; |
| + host->ServeChannel(handle); |
|
koz (OOO until 15th September)
2013/03/14 23:51:05
nit: make this one line?
Also, add a comment sayi
jeremya
2013/03/15 02:24:14
Done.
|
| +} |
| + |
| +} // namespace |
| + |
| +AppShimHostController::AppShimHostController() : factory_(NULL) { |
|
koz (OOO until 15th September)
2013/03/14 23:51:05
DCHECK() to communicate what thread this is suppos
jeremya
2013/03/15 02:24:14
Done.
|
| + BrowserThread::PostTask( |
| + BrowserThread::FILE, FROM_HERE, |
| + base::Bind(&AppShimHostController::InitOnFileThread, |
| + base::Unretained(this))); |
| +} |
| + |
| +AppShimHostController::~AppShimHostController() { |
| + delete factory_; |
|
koz (OOO until 15th September)
2013/03/14 23:51:05
scoped_ptr for factory_.
jeremya
2013/03/15 02:24:14
Done.
|
| +} |
| + |
| +void AppShimHostController::InitOnFileThread() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + base::FilePath user_data_dir; |
| + if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { |
| + LOG(ERROR) << "Couldn't get user data directory while creating App Shim " |
| + << "Host controller."; |
| + return; |
| + } |
| + base::FilePath socket_path = |
| + user_data_dir.Append(app_mode::kAppShimSocketName); |
| + factory_ = new IPC::ChannelFactory(socket_path, this); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&AppShimHostController::ListenOnIOThread, |
| + base::Unretained(this))); |
| +} |
| + |
| +void AppShimHostController::ListenOnIOThread() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + factory_->Listen(); |
| +} |
| + |
| +void AppShimHostController::OnClientConnected( |
| + const IPC::ChannelHandle& handle) { |
| + // called on IO thread |
|
koz (OOO until 15th September)
2013/03/14 23:51:05
DCHECK() that we're on the IO thread rather than t
jeremya
2013/03/15 02:24:14
Done.
|
| + BrowserThread::PostTask( |
| + BrowserThread::UI, FROM_HERE, |
| + base::Bind(&CreateAppShimHost, handle)); |
| +} |
| + |
| +void AppShimHostController::OnListenError() { |
| + // TODO(jeremya): set a timeout and attempt to reconstruct the channel. |
| +} |