summaryrefslogtreecommitdiffstats
path: root/chrome/browser/policy/user_policy_token_loader.h
blob: 7f32eadef188978da3232a8df847fc0ccdf241db (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
// Copyright (c) 2012 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.

#ifndef CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_LOADER_H_
#define CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_LOADER_H_

#include <string>

#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"

namespace policy {

// Handles disk access and threading details for loading and storing tokens.
// This is legacy-support code that reads the token from its prior location
// within the profile directory new code keeps the token in the policy blob
// maintained by session_manager.
class UserPolicyTokenLoader
    : public base::RefCountedThreadSafe<UserPolicyTokenLoader> {
 public:
  // Callback interface for reporting a successful load.
  class Delegate {
   public:
    virtual ~Delegate();
    virtual void OnTokenLoaded(const std::string& token,
                               const std::string& device_id) = 0;
  };

  UserPolicyTokenLoader(const base::WeakPtr<Delegate>& delegate,
                        const base::FilePath& cache_file);

  // Starts loading the disk cache. After the load is finished, the result is
  // reported through the delegate.
  void Load();

 private:
  friend class base::RefCountedThreadSafe<UserPolicyTokenLoader>;
  ~UserPolicyTokenLoader();

  void LoadOnFileThread();
  void NotifyOnUIThread(const std::string& token,
                        const std::string& device_id);

  const base::WeakPtr<Delegate> delegate_;
  const base::FilePath cache_file_;

  DISALLOW_COPY_AND_ASSIGN(UserPolicyTokenLoader);
};

}  // namespace policy

#endif  // CHROME_BROWSER_POLICY_USER_POLICY_TOKEN_LOADER_H_