| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This file defines the "sync API", an interface to the syncer | 5 // This file defines the "sync API", an interface to the syncer |
| 6 // backend that exposes (1) the core functionality of maintaining a consistent | 6 // backend that exposes (1) the core functionality of maintaining a consistent |
| 7 // local snapshot of a hierarchical object set; (2) a means to transactionally | 7 // local snapshot of a hierarchical object set; (2) a means to transactionally |
| 8 // access and modify those objects; (3) a means to control client/server | 8 // access and modify those objects; (3) a means to control client/server |
| 9 // synchronization tasks, namely: pushing local object modifications to a | 9 // synchronization tasks, namely: pushing local object modifications to a |
| 10 // server, pulling nonlocal object modifications from a server to this client, | 10 // server, pulling nonlocal object modifications from a server to this client, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "build/build_config.h" | 45 #include "build/build_config.h" |
| 46 #include "chrome/browser/google_service_auth_error.h" | 46 #include "chrome/browser/google_service_auth_error.h" |
| 47 #include "googleurl/src/gurl.h" | 47 #include "googleurl/src/gurl.h" |
| 48 | 48 |
| 49 // The MSVC compiler for Windows requires that any classes exported by, or | 49 // The MSVC compiler for Windows requires that any classes exported by, or |
| 50 // imported from, a dynamic library be marked with an appropriate | 50 // imported from, a dynamic library be marked with an appropriate |
| 51 // __declspec() decoration. However, we currently use static linkage | 51 // __declspec() decoration. However, we currently use static linkage |
| 52 // on all platforms. | 52 // on all platforms. |
| 53 #define SYNC_EXPORT | 53 #define SYNC_EXPORT |
| 54 | 54 |
| 55 namespace browser_sync { |
| 56 class ModelSafeWorkerRegistrar; |
| 57 } |
| 58 |
| 55 // Forward declarations of internal class types so that sync API objects | 59 // Forward declarations of internal class types so that sync API objects |
| 56 // may have opaque pointers to these types. | 60 // may have opaque pointers to these types. |
| 57 namespace syncable { | 61 namespace syncable { |
| 58 class BaseTransaction; | 62 class BaseTransaction; |
| 59 class DirectoryManager; | 63 class DirectoryManager; |
| 60 class Entry; | 64 class Entry; |
| 61 class MutableEntry; | 65 class MutableEntry; |
| 62 class ReadTransaction; | 66 class ReadTransaction; |
| 63 class ScopedDirLookup; | 67 class ScopedDirLookup; |
| 64 class WriteTransaction; | 68 class WriteTransaction; |
| 65 } | 69 } |
| 66 | 70 |
| 67 namespace sync_api { | 71 namespace sync_api { |
| 68 | 72 |
| 69 // Forward declarations of classes to be defined later in this file. | 73 // Forward declarations of classes to be defined later in this file. |
| 70 class BaseTransaction; | 74 class BaseTransaction; |
| 71 class HttpPostProviderFactory; | 75 class HttpPostProviderFactory; |
| 72 class ModelSafeWorkerInterface; | |
| 73 class SyncManager; | 76 class SyncManager; |
| 74 class WriteTransaction; | 77 class WriteTransaction; |
| 75 struct UserShare; | 78 struct UserShare; |
| 76 | 79 |
| 77 // A valid BaseNode will never have an ID of zero. | 80 // A valid BaseNode will never have an ID of zero. |
| 78 static const int64 kInvalidId = 0; | 81 static const int64 kInvalidId = 0; |
| 79 | 82 |
| 80 // BaseNode wraps syncable::Entry, and corresponds to a single object's state. | 83 // BaseNode wraps syncable::Entry, and corresponds to a single object's state. |
| 81 // This, like syncable::Entry, is intended for use on the stack. A valid | 84 // This, like syncable::Entry, is intended for use on the stack. A valid |
| 82 // transaction is necessary to create a BaseNode or any of its children. | 85 // transaction is necessary to create a BaseNode or any of its children. |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // As a fallback when no cached auth information is available, try to | 505 // As a fallback when no cached auth information is available, try to |
| 503 // bootstrap authentication using |lsid|, if it isn't empty. | 506 // bootstrap authentication using |lsid|, if it isn't empty. |
| 504 bool Init(const FilePath& database_location, | 507 bool Init(const FilePath& database_location, |
| 505 const char* sync_server_and_path, | 508 const char* sync_server_and_path, |
| 506 int sync_server_port, | 509 int sync_server_port, |
| 507 const char* gaia_service_id, | 510 const char* gaia_service_id, |
| 508 const char* gaia_source, | 511 const char* gaia_source, |
| 509 bool use_ssl, | 512 bool use_ssl, |
| 510 HttpPostProviderFactory* post_factory, | 513 HttpPostProviderFactory* post_factory, |
| 511 HttpPostProviderFactory* auth_post_factory, | 514 HttpPostProviderFactory* auth_post_factory, |
| 512 ModelSafeWorkerInterface* model_safe_worker, | 515 browser_sync::ModelSafeWorkerRegistrar* registrar, |
| 513 bool attempt_last_user_authentication, | 516 bool attempt_last_user_authentication, |
| 514 const char* user_agent, | 517 const char* user_agent, |
| 515 const char* lsid); | 518 const char* lsid); |
| 516 | 519 |
| 517 // Returns the username last used for a successful authentication. | 520 // Returns the username last used for a successful authentication. |
| 518 // Returns empty if there is no such username. | 521 // Returns empty if there is no such username. |
| 519 const std::string& GetAuthenticatedUsername(); | 522 const std::string& GetAuthenticatedUsername(); |
| 520 | 523 |
| 521 // Submit credentials to GAIA for verification and start the | 524 // Submit credentials to GAIA for verification and start the |
| 522 // syncing process on success. On success, both |username| and the obtained | 525 // syncing process on success. On success, both |username| and the obtained |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 | 635 |
| 633 // When the interface is no longer needed (ready to be cleaned up), clients | 636 // When the interface is no longer needed (ready to be cleaned up), clients |
| 634 // must call Destroy(). | 637 // must call Destroy(). |
| 635 // This allows actual HttpPostProvider subclass implementations to be | 638 // This allows actual HttpPostProvider subclass implementations to be |
| 636 // reference counted, which is useful if a particular implementation uses | 639 // reference counted, which is useful if a particular implementation uses |
| 637 // multiple threads to serve network requests. | 640 // multiple threads to serve network requests. |
| 638 virtual void Destroy(HttpPostProviderInterface* http) = 0; | 641 virtual void Destroy(HttpPostProviderInterface* http) = 0; |
| 639 virtual ~HttpPostProviderFactory() { } | 642 virtual ~HttpPostProviderFactory() { } |
| 640 }; | 643 }; |
| 641 | 644 |
| 642 // A class syncapi clients should use whenever the underlying model is bound to | |
| 643 // a particular thread in the embedding application. This exposes an interface | |
| 644 // by which any model-modifying invocations will be forwarded to the | |
| 645 // appropriate thread in the embedding application. | |
| 646 // "model safe" refers to not allowing an embedding application model to fall | |
| 647 // out of sync with the syncable::Directory due to race conditions. | |
| 648 class ModelSafeWorkerInterface { | |
| 649 public: | |
| 650 virtual ~ModelSafeWorkerInterface() { } | |
| 651 // A Visitor is passed to CallDoWorkFromModelSafeThreadAndWait invocations, | |
| 652 // and it's sole purpose is to provide a way for the ModelSafeWorkerInterface | |
| 653 // implementation to actually _do_ the work required, by calling the only | |
| 654 // method on this class, DoWork(). | |
| 655 class Visitor { | |
| 656 public: | |
| 657 virtual ~Visitor() { } | |
| 658 // When on a model safe thread, this should be called to have the syncapi | |
| 659 // actually perform the work needing to be done. | |
| 660 virtual void DoWork() = 0; | |
| 661 }; | |
| 662 // Subclasses should implement to invoke DoWork on |visitor| once on a thread | |
| 663 // appropriate for data model modifications. | |
| 664 // While it doesn't hurt, the impl does not need to be re-entrant (for now). | |
| 665 // Note: |visitor| is owned by caller. | |
| 666 virtual void CallDoWorkFromModelSafeThreadAndWait(Visitor* visitor) = 0; | |
| 667 }; | |
| 668 | |
| 669 } // namespace sync_api | 645 } // namespace sync_api |
| 670 | 646 |
| 671 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ | 647 #endif // CHROME_BROWSER_SYNC_ENGINE_SYNCAPI_H_ |
| OLD | NEW |