summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/enterprise_extension_observer.cc
blob: c380ca62746f81378edeb4ee0fd6e81c194d599a (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
// Copyright (c) 2011 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 "chrome/browser/chromeos/enterprise_extension_observer.h"

#include "base/bind.h"
#include "base/file_util.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
#include "chrome/browser/chromeos/dbus/session_manager_client.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/browser_thread.h"

namespace chromeos {

EnterpriseExtensionObserver::EnterpriseExtensionObserver(Profile* profile)
    : profile_(profile) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  registrar_.Add(this,
                 chrome::NOTIFICATION_EXTENSION_INSTALLED,
                 content::Source<Profile>(profile_));
}

void EnterpriseExtensionObserver::Observe(
    int type,
    const content::NotificationSource& source,
    const content::NotificationDetails& details) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  DCHECK(type == chrome::NOTIFICATION_EXTENSION_INSTALLED);
  if (content::Source<Profile>(source).ptr() != profile_) {
    return;
  }
  Extension* extension = content::Details<Extension>(details).ptr();
  if (extension->location() != Extension::EXTERNAL_POLICY_DOWNLOAD) {
    return;
  }
  BrowserThread::PostTask(
      BrowserThread::FILE,
      FROM_HERE,
      base::Bind(
          &EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd,
          extension->path()));
}

// static
void EnterpriseExtensionObserver::CheckExtensionAndNotifyEntd(
    const FilePath& path) {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
  if (file_util::PathExists(
      path.Append(FILE_PATH_LITERAL("isa-cros-policy")))) {
    BrowserThread::PostTask(
        BrowserThread::UI,
        FROM_HERE,
        base::Bind(&EnterpriseExtensionObserver::NotifyEntd));
  }
}

// static
void EnterpriseExtensionObserver::NotifyEntd() {
  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
  DBusThreadManager::Get()->session_manager_client()->RestartEntd();
}

}  // namespace chromeos