Home | History | Annotate | Download | only in identity
      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_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_
      7 
      8 #include <list>
      9 #include <map>
     10 #include <set>
     11 #include <string>
     12 
     13 #include "chrome/browser/extensions/api/identity/extension_token_key.h"
     14 
     15 namespace extensions {
     16 
     17 // getAuthToken requests are serialized to avoid excessive traffic to
     18 // GAIA and to consolidate UI pop-ups. IdentityMintRequestQueue
     19 // maitains a set of queues, one for each RequestKey.
     20 //
     21 // The queue calls StartMintToken on each Request when it reaches the
     22 // head of the line.
     23 //
     24 // The queue does not own Requests. Request pointers must be valid
     25 // until they are removed from the queue with RequestComplete.
     26 class IdentityMintRequestQueue {
     27  public:
     28   enum MintType {
     29     MINT_TYPE_NONINTERACTIVE,
     30     MINT_TYPE_INTERACTIVE
     31   };
     32 
     33   IdentityMintRequestQueue();
     34   virtual ~IdentityMintRequestQueue();
     35 
     36   class Request {
     37    public:
     38     virtual ~Request() {}
     39     virtual void StartMintToken(IdentityMintRequestQueue::MintType type) = 0;
     40   };
     41 
     42   // Adds a request to the queue specified by the token key.
     43   void RequestStart(IdentityMintRequestQueue::MintType type,
     44                     const ExtensionTokenKey& key,
     45                     IdentityMintRequestQueue::Request* request);
     46   // Removes a request from the queue specified by the token key.
     47   void RequestComplete(IdentityMintRequestQueue::MintType type,
     48                        const ExtensionTokenKey& key,
     49                        IdentityMintRequestQueue::Request* request);
     50   bool empty(IdentityMintRequestQueue::MintType type,
     51              const ExtensionTokenKey& key);
     52 
     53  private:
     54   typedef std::list<IdentityMintRequestQueue::Request*> RequestQueue;
     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_;
     61 };
     62 
     63 }  // namespace extensions
     64 
     65 #endif  // CHROME_BROWSER_EXTENSIONS_API_IDENTITY_IDENTITY_MINT_QUEUE_H_
     66