OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
| 13 #include "chrome/browser/extensions/api/identity/extension_token_key.h" |
| 14 |
13 namespace extensions { | 15 namespace extensions { |
14 | 16 |
15 // getAuthToken requests are serialized to avoid excessive traffic to | 17 // getAuthToken requests are serialized to avoid excessive traffic to |
16 // GAIA and to consolidate UI pop-ups. IdentityMintRequestQueue | 18 // GAIA and to consolidate UI pop-ups. IdentityMintRequestQueue |
17 // maitains a set of queues, one for each RequestKey. | 19 // maitains a set of queues, one for each RequestKey. |
18 // | 20 // |
19 // The queue calls StartMintToken on each Request when it reaches the | 21 // The queue calls StartMintToken on each Request when it reaches the |
20 // head of the line. | 22 // head of the line. |
21 // | 23 // |
22 // The queue does not own Requests. Request pointers must be valid | 24 // The queue does not own Requests. Request pointers must be valid |
23 // until they are removed from the queue with RequestComplete. | 25 // until they are removed from the queue with RequestComplete. |
24 class IdentityMintRequestQueue { | 26 class IdentityMintRequestQueue { |
25 public: | 27 public: |
26 enum MintType { | 28 enum MintType { |
27 MINT_TYPE_NONINTERACTIVE, | 29 MINT_TYPE_NONINTERACTIVE, |
28 MINT_TYPE_INTERACTIVE | 30 MINT_TYPE_INTERACTIVE |
29 }; | 31 }; |
30 | 32 |
31 IdentityMintRequestQueue(); | 33 IdentityMintRequestQueue(); |
32 virtual ~IdentityMintRequestQueue(); | 34 virtual ~IdentityMintRequestQueue(); |
33 | 35 |
34 class Request { | 36 class Request { |
35 public: | 37 public: |
36 virtual ~Request() {} | 38 virtual ~Request() {} |
37 virtual void StartMintToken(IdentityMintRequestQueue::MintType type) = 0; | 39 virtual void StartMintToken(IdentityMintRequestQueue::MintType type) = 0; |
38 }; | 40 }; |
39 | 41 |
40 struct RequestKey { | 42 // Adds a request to the queue specified by the token key. |
41 RequestKey(IdentityMintRequestQueue::MintType type, | |
42 const std::string& extension_id, | |
43 const std::set<std::string> scopes); | |
44 ~RequestKey(); | |
45 bool operator<(const RequestKey& rhs) const; | |
46 IdentityMintRequestQueue::MintType type; | |
47 std::string extension_id; | |
48 std::set<std::string> scopes; | |
49 }; | |
50 | |
51 // Adds a request to the queue specified by the id and scopes. | |
52 void RequestStart(IdentityMintRequestQueue::MintType type, | 43 void RequestStart(IdentityMintRequestQueue::MintType type, |
53 const std::string& extension_id, | 44 const ExtensionTokenKey& key, |
54 const std::set<std::string> scopes, | |
55 IdentityMintRequestQueue::Request* request); | 45 IdentityMintRequestQueue::Request* request); |
56 // Removes a request from the queue specified by the id and scopes. | 46 // Removes a request from the queue specified by the token key. |
57 void RequestComplete(IdentityMintRequestQueue::MintType type, | 47 void RequestComplete(IdentityMintRequestQueue::MintType type, |
58 const std::string& extension_id, | 48 const ExtensionTokenKey& key, |
59 const std::set<std::string> scopes, | |
60 IdentityMintRequestQueue::Request* request); | 49 IdentityMintRequestQueue::Request* request); |
61 bool empty(IdentityMintRequestQueue::MintType type, | 50 bool empty(IdentityMintRequestQueue::MintType type, |
62 const std::string& extension_id, | 51 const ExtensionTokenKey& key); |
63 const std::set<std::string> scopes) const; | |
64 | 52 |
65 private: | 53 private: |
66 typedef std::list<IdentityMintRequestQueue::Request*> RequestList; | 54 typedef std::list<IdentityMintRequestQueue::Request*> RequestQueue; |
67 std::map<RequestKey, RequestList> request_queue_; | 55 typedef std::map<const ExtensionTokenKey, RequestQueue> RequestQueueMap; |
| 56 |
| 57 RequestQueueMap& GetRequestQueueMap(IdentityMintRequestQueue::MintType type); |
| 58 |
| 59 RequestQueueMap interactive_request_queue_map_; |
| 60 RequestQueueMap noninteractive_request_queue_map_; |
68 }; | 61 }; |
69 | 62 |
70 | |
71 } // namespace extensions | 63 } // namespace extensions |
72 | 64 |
73 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_ | 65 #endif // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_ |
OLD | NEW |