Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(265)

Side by Side Diff: chrome/browser/supervised_user/child_accounts/family_info_fetcher.h

Issue 783083002: Add support for child accounts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove CrOS for now Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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_SUPERVISED_USER_CHILD_ACCOUNTS_FAMILY_INFO_FETCHER_H_
6 #define CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_FAMILY_INFO_FETCHER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "google_apis/gaia/oauth2_token_service.h"
15 #include "net/url_request/url_fetcher.h"
16 #include "net/url_request/url_fetcher_delegate.h"
17
18 namespace base {
19 class DictionaryValue;
20 class ListValue;
21 class Time;
22 }
23
24 namespace net {
25 class URLRequestContextGetter;
26 }
27
28 class FamilyInfoFetcher : public OAuth2TokenService::Observer,
29 public OAuth2TokenService::Consumer,
30 public net::URLFetcherDelegate {
31 public:
32 enum ErrorCode {
33 TOKEN_ERROR, // Failed to get OAuth2 token.
34 NETWORK_ERROR, // Network failure.
35 SERVICE_ERROR, // Service returned an error or malformed reply.
36 };
37 enum FamilyMemberRole {
38 HEAD_OF_HOUSEHOLD = 0,
39 PARENT,
40 MEMBER,
41 CHILD
42 };
43 struct FamilyProfile {
44 FamilyProfile();
45 FamilyProfile(const std::string& id, const std::string& name);
46 ~FamilyProfile();
47 std::string id;
48 std::string name;
49 };
50 struct FamilyMember {
51 FamilyMember();
52 FamilyMember(const std::string& obfuscated_gaia_id,
53 FamilyMemberRole role,
54 const std::string& display_name,
55 const std::string& email,
56 const std::string& profile_url,
57 const std::string& profile_image_url);
58 ~FamilyMember();
59 std::string obfuscated_gaia_id;
60 FamilyMemberRole role;
61 // All of the following may be empty.
62 std::string display_name;
63 std::string email;
64 std::string profile_url;
65 std::string profile_image_url;
66 };
67
68 class Consumer {
69 public:
70 virtual void OnGetFamilyProfileSuccess(const FamilyProfile& family) {}
71 virtual void OnGetFamilyMembersSuccess(
72 const std::vector<FamilyMember>& members) {}
73 virtual void OnFailure(ErrorCode error) {}
74 };
75
76 FamilyInfoFetcher(Consumer* consumer,
77 const std::string& account_id,
78 OAuth2TokenService* token_service,
79 net::URLRequestContextGetter* request_context);
80 virtual ~FamilyInfoFetcher();
81
82 // Public so tests can use them.
83 static std::string RoleToString(FamilyMemberRole role);
84 static bool StringToRole(const std::string& str, FamilyMemberRole* role);
85
86 void StartGetFamilyProfile();
87 void StartGetFamilyMembers();
88
89 private:
90 // OAuth2TokenService::Observer implementation:
91 virtual void OnRefreshTokenAvailable(const std::string& account_id) override;
92 virtual void OnRefreshTokensLoaded() override;
93
94 // OAuth2TokenService::Consumer implementation:
95 virtual void OnGetTokenSuccess(const OAuth2TokenService::Request* request,
96 const std::string& access_token,
97 const base::Time& expiration_time) override;
98 virtual void OnGetTokenFailure(const OAuth2TokenService::Request* request,
99 const GoogleServiceAuthError& error) override;
100
101 // net::URLFetcherDelegate implementation.
102 virtual void OnURLFetchComplete(const net::URLFetcher* source) override;
103
104 static bool ParseMembers(const base::ListValue* list,
105 std::vector<FamilyMember>* members);
106 static bool ParseMember(const base::DictionaryValue* dict,
107 FamilyMember* member);
108 static void ParseProfile(const base::DictionaryValue* dict,
109 FamilyMember* member);
110
111 void StartFetching();
112 void StartFetchingAccessToken();
113 void FamilyProfileFetched(const std::string& response);
114 void FamilyMembersFetched(const std::string& response);
115
116 Consumer* consumer_;
117 const std::string account_id_;
118 OAuth2TokenService* token_service_;
119 net::URLRequestContextGetter* request_context_;
120
121 std::string request_suffix_;
122 net::URLFetcher::RequestType request_type_;
123 scoped_ptr<OAuth2TokenService::Request> access_token_request_;
124 std::string access_token_;
125 bool access_token_expired_;
126 scoped_ptr<net::URLFetcher> url_fetcher_;
127
128 DISALLOW_COPY_AND_ASSIGN(FamilyInfoFetcher);
129 };
130
131 #endif // CHROME_BROWSER_SUPERVISED_USER_CHILD_ACCOUNTS_FAMILY_INFO_FETCHER_H_
132
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698