{"action":"created","issue":{"url":"https://api.github.com/repos/w3c/encrypted-media/issues/14","repository_url":"https://api.github.com/repos/w3c/encrypted-media","labels_url":"https://api.github.com/repos/w3c/encrypted-media/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/w3c/encrypted-media/issues/14/comments","events_url":"https://api.github.com/repos/w3c/encrypted-media/issues/14/events","html_url":"https://github.com/w3c/encrypted-media/issues/14","id":54504919,"number":14,"title":"Consider changing how the MediaKeySession method algorithms run other algorithms to more accurately reflect implementations","user":{"login":"ddorwin","id":9738764,"avatar_url":"https://avatars.githubusercontent.com/u/9738764?v=3","gravatar_id":"","url":"https://api.github.com/users/ddorwin","html_url":"https://github.com/ddorwin","followers_url":"https://api.github.com/users/ddorwin/followers","following_url":"https://api.github.com/users/ddorwin/following{/other_user}","gists_url":"https://api.github.com/users/ddorwin/gists{/gist_id}","starred_url":"https://api.github.com/users/ddorwin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ddorwin/subscriptions","organizations_url":"https://api.github.com/users/ddorwin/orgs","repos_url":"https://api.github.com/users/ddorwin/repos","events_url":"https://api.github.com/users/ddorwin/events{/privacy}","received_events_url":"https://api.github.com/users/ddorwin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/w3c/encrypted-media/milestones/1","html_url":"https://github.com/w3c/encrypted-media/milestones/V1","labels_url":"https://api.github.com/repos/w3c/encrypted-media/milestones/1/labels","id":1356261,"number":1,"title":"V1","description":null,"creator":{"login":"jdsmith3000","id":8323871,"avatar_url":"https://avatars.githubusercontent.com/u/8323871?v=3","gravatar_id":"","url":"https://api.github.com/users/jdsmith3000","html_url":"https://github.com/jdsmith3000","followers_url":"https://api.github.com/users/jdsmith3000/followers","following_url":"https://api.github.com/users/jdsmith3000/following{/other_user}","gists_url":"https://api.github.com/users/jdsmith3000/gists{/gist_id}","starred_url":"https://api.github.com/users/jdsmith3000/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdsmith3000/subscriptions","organizations_url":"https://api.github.com/users/jdsmith3000/orgs","repos_url":"https://api.github.com/users/jdsmith3000/repos","events_url":"https://api.github.com/users/jdsmith3000/events{/privacy}","received_events_url":"https://api.github.com/users/jdsmith3000/received_events","type":"User","site_admin":false},"open_issues":16,"closed_issues":48,"state":"open","created_at":"2015-10-14T21:50:00Z","updated_at":"2016-05-01T04:55:07Z","due_on":null,"closed_at":null},"comments":10,"created_at":"2015-01-15T21:12:47Z","updated_at":"2016-05-13T15:16:07Z","closed_at":null,"body":"The `generateRequest()`, `load()`, `update()`, and `remove()` algorithms all run other algorithms **after** the CDM step and **before** resolving the promise. This has the advantage of separating responsibilities, **ensuring all failures are caught before firing events**, and having promise resolution as the last step, but it seems unlikely to accurately represent implementations, possibly in a way that is observable to applications. We should consider whether there is a better way organize things.\r\n\r\nI'll use the current `load()` algorithm as an example.\r\nIf the CDM steps succeed, the user agent has been provided with a message. The user agent then:\r\n 1. Initializes some application-observable state (`sessionId` attribute and _callable_ state)\r\n 2. May run the usable keys changed algorithm, which fires an event at the session.\r\n 3. Runs the update expiration algorithm, which updates the expiration attribute.\r\n 4. May run the queue a \"message\" event algorithm with the message provided by the CDM.\r\n 5. Resolves the promise.\r\n\r\nHowever, a likely implementation pattern would be one of the following:\r\nI. CDM reports success once all operations have completed.\r\n 1. User agent asks the CDM to load a session.\r\n   1. The CDM loads the session.\r\n   1. The CDM triggers the usable keys changed algorithm.\r\n   1. The CDM triggers the update expiration algorithm.\r\n   1. The CDM provides a message to be provided to the application.\r\n   1. The CDM reports success to the user agent.\r\n 2. The user agent initializes some application-observable state (`sessionId` attribute and _callable_ state).\r\n 3. The user agent resolves the promise.\r\n\r\nII. CDM reports success after processing the request but before all operations have completed.\r\n 1. User agent asks the CDM to load a session.\r\n 2. The CDM loads the session and reports success to the user agent.\r\n 3. The user agent initializes some application-observable state (`sessionId` attribute and _callable_ state).\r\n 4. The user agent resolves the promise.\r\n 5. In parallel or subsequently:\r\n   1. The CDM triggers the usable keys changed algorithm.\r\n   1. The CDM triggers the update expiration algorithm.\r\n   1. The CDM provides a message to be provided to the application.\r\n\r\nConverting either of those implementation patterns to the observable behavior specified in the current algorithm likely requires one of the following undesirable solutions:\r\n 1. Caching requests from the CDM until the CDM reports success.\r\n 2. Session initialization-specific mechanisms for reporting key updates, expiration, and messages.\r\nAn example of (1) would be a `CompleteLoad()` method that takes all of these values rather than reusing existing `SendMessage()`, etc. methods.\r\n\r\n\r\nWe should also consider the desired application-observable behavior.\r\n* Not getting events until the load succeeds is nice.\r\n* However, it might be weird to get events from an operation before it has succeeded.\r\n* The callable state must be set to true before any events are fired to ensure that the application is able to respond to the event by calling one of the methods.\r\n* There is currently a potential race condition between the `generateRequest()` promise being resolved, indicating that sessionId is valid, and the application receiving the license request message.\r\n* Since the expiration attribute does not currently have an event, updating the expiration attribute before resolving the promise in the `load()` and `update()` algorithms provides a deterministic place for applications to check the expiration.\r\n  - Maybe `Object.observe()` could be used to detect changes to this attribute instead. Would we get this behavior for free?\r\n\r\n\r\nNote: The `update()` algorithm currently has the CDM running the the usable keys changed algorithm and update expiration algorithm rather than deferring these to the user agent. This is more consistent with implementation pattern (I) above. Regardless of the outcome of this bug, the algorithms should be consistent. We should change the steps in those algorithms to be “Provide the user agent with X and have it run the following steps.”\r\n\r\n[Migrated from https://www.w3.org/Bugs/Public/show_bug.cgi?id=27138 with only formatting and numbering changes.]"},"comment":{"url":"https://api.github.com/repos/w3c/encrypted-media/issues/comments/219073473","html_url":"https://github.com/w3c/encrypted-media/issues/14#issuecomment-219073473","issue_url":"https://api.github.com/repos/w3c/encrypted-media/issues/14","id":219073473,"user":{"login":"mwatson2","id":7593867,"avatar_url":"https://avatars.githubusercontent.com/u/7593867?v=3","gravatar_id":"","url":"https://api.github.com/users/mwatson2","html_url":"https://github.com/mwatson2","followers_url":"https://api.github.com/users/mwatson2/followers","following_url":"https://api.github.com/users/mwatson2/following{/other_user}","gists_url":"https://api.github.com/users/mwatson2/gists{/gist_id}","starred_url":"https://api.github.com/users/mwatson2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mwatson2/subscriptions","organizations_url":"https://api.github.com/users/mwatson2/orgs","repos_url":"https://api.github.com/users/mwatson2/repos","events_url":"https://api.github.com/users/mwatson2/events{/privacy}","received_events_url":"https://api.github.com/users/mwatson2/received_events","type":"User","site_admin":false},"created_at":"2016-05-13T15:16:07Z","updated_at":"2016-05-13T15:16:07Z","body":"I've reviewed the discussion on this one and I don't believe there are any remaining issues to address here. @ddorwin, @steelejoe, @cpearce Do you agree ?"}}