forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_shim_host_manager_mac.mm
85 lines (70 loc) · 2.73 KB
/
app_shim_host_manager_mac.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 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_manager_mac.h"
#include "apps/app_shim/app_shim_handler_mac.h"
#include "apps/app_shim/app_shim_host_mac.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 "chrome/common/mac/app_mode_common.h"
using content::BrowserThread;
namespace {
void CreateAppShimHost(const IPC::ChannelHandle& handle) {
// AppShimHost takes ownership of itself.
(new AppShimHost)->ServeChannel(handle);
}
} // namespace
const base::FilePath* AppShimHostManager::g_override_user_data_dir_ = NULL;
AppShimHostManager::AppShimHostManager() {}
void AppShimHostManager::Init() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
apps::AppShimHandler::SetDefaultHandler(&extension_app_shim_handler_);
BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&AppShimHostManager::InitOnFileThread, this));
}
AppShimHostManager::~AppShimHostManager() {
apps::AppShimHandler::SetDefaultHandler(NULL);
}
void AppShimHostManager::InitOnFileThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
base::FilePath user_data_dir;
if (g_override_user_data_dir_) {
user_data_dir = *g_override_user_data_dir_;
} else if (!PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) {
LOG(ERROR) << "Couldn't get user data directory while creating App Shim "
<< "Host manager.";
return;
}
base::FilePath socket_path =
user_data_dir.Append(app_mode::kAppShimSocketName);
factory_.reset(new IPC::ChannelFactory(socket_path, this));
BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(&AppShimHostManager::ListenOnIOThread, this));
}
void AppShimHostManager::ListenOnIOThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
if (!factory_->Listen()) {
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&AppShimHostManager::OnListenError, this));
}
}
void AppShimHostManager::OnClientConnected(
const IPC::ChannelHandle& handle) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&CreateAppShimHost, handle));
}
void AppShimHostManager::OnListenError() {
// TODO(tapted): Set a timeout and attempt to reconstruct the channel. Until
// cases where the error could occur are better known, just reset the factory
// to allow failure to be communicated via the test API.
factory_.reset();
}