- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / policy / user_policy_token_loader.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TOKEN_LOADER_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TOKEN_LOADER_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14
15 namespace base {
16 class SequencedTaskRunner;
17 }
18
19 namespace policy {
20
21 // Handles disk access and threading details for loading and storing tokens.
22 // This is legacy-support code that reads the token from its prior location
23 // within the profile directory new code keeps the token in the policy blob
24 // maintained by session_manager.
25 class UserPolicyTokenLoader
26     : public base::RefCountedThreadSafe<UserPolicyTokenLoader> {
27  public:
28   // Callback interface for reporting a successful load.
29   class Delegate {
30    public:
31     virtual ~Delegate();
32     virtual void OnTokenLoaded(const std::string& token,
33                                const std::string& device_id) = 0;
34   };
35
36   UserPolicyTokenLoader(
37       const base::WeakPtr<Delegate>& delegate,
38       const base::FilePath& cache_file,
39       scoped_refptr<base::SequencedTaskRunner> background_task_runner);
40
41   // Starts loading the disk cache. After the load is finished, the result is
42   // reported through the delegate.
43   void Load();
44
45  private:
46   friend class base::RefCountedThreadSafe<UserPolicyTokenLoader>;
47   ~UserPolicyTokenLoader();
48
49   void LoadOnBackgroundThread();
50   void NotifyOnOriginThread(const std::string& token,
51                         const std::string& device_id);
52
53   const base::WeakPtr<Delegate> delegate_;
54   const base::FilePath cache_file_;
55   scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
56   scoped_refptr<base::SequencedTaskRunner> background_task_runner_;
57
58   DISALLOW_COPY_AND_ASSIGN(UserPolicyTokenLoader);
59 };
60
61 }  // namespace policy
62
63 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_USER_POLICY_TOKEN_LOADER_H_