summaryrefslogtreecommitdiffstats
path: root/components/profile_service/profile_app.cc
blob: 27491db5e910d27946721e9031860a493591c71b (plain)
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
// Copyright 2016 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 "components/profile_service/profile_app.h"

#include "base/lazy_instance.h"
#include "components/leveldb/leveldb_service_impl.h"
#include "components/profile_service/profile_service_impl.h"
#include "mojo/shell/public/cpp/connection.h"

namespace profile {

namespace {

base::LazyInstance<std::map<std::string, base::FilePath>>
    g_user_id_to_data_dir = LAZY_INSTANCE_INITIALIZER;

}  // namespace

scoped_ptr<mojo::ShellClient> CreateProfileApp() {
  return make_scoped_ptr(new ProfileApp);
}

ProfileApp::ProfileApp()
    : lock_table_(new filesystem::LockTable) {
}

ProfileApp::~ProfileApp() {}

// static
void ProfileApp::AssociateMojoUserIDWithProfileDir(
    const std::string& user_id,
    const base::FilePath& profile_data_dir) {
  g_user_id_to_data_dir.Get()[user_id] = profile_data_dir;
}

void ProfileApp::Initialize(mojo::Connector* connector,
                            const mojo::Identity& identity,
                            uint32_t id) {
  tracing_.Initialize(connector, identity.name());
  leveldb_service_.reset(new leveldb::LevelDBServiceImpl);

  auto it = g_user_id_to_data_dir.Get().find(identity.user_id());
  DCHECK(it != g_user_id_to_data_dir.Get().end());
  profile_data_dir_ = it->second;
}

bool ProfileApp::AcceptConnection(mojo::Connection* connection) {
  connection->AddInterface<leveldb::LevelDBService>(this);
  connection->AddInterface<ProfileService>(this);
  return true;
}

void ProfileApp::Create(mojo::Connection* connection,
                        ProfileServiceRequest request) {
  // No, we need one of these per connection.
  new ProfileServiceImpl(connection,
                         std::move(request),
                         profile_data_dir_,
                         lock_table_.get());
}

void ProfileApp::Create(mojo::Connection* connection,
                        leveldb::LevelDBServiceRequest request) {
  leveldb_bindings_.AddBinding(leveldb_service_.get(), std::move(request));
}

}  // namespace profile